I'm have trouble getting this signal thing working. I have a receive and send script. It seems to work randomly, I run the receive script and then the send script and it seems to work most of the time. How ever sometimes it will randomly give me:
Traceback (most recent call last):
File "sender.py", line 8, in <module>
os.kill(PID, signal.SIGUSR1)
OSError: [Errno 3] No such process
or
File "sender.py", line 8, in <module>
os.kill(PID, signal.SIGUSR1)
OSError: [Errno 1] Operation not permitted
Which makes no sense since I could have 2 consoles both running the send script and one sending the signal successfully whilst the other giving that error even though both are getting the same PID. So not quite sure what I'm doing wrong. Here are both the scripts
recieve:
import time
import signal
import os
with open("processid.txt","w+") as processPID:
processPID.write(str(os.getpid()))
received_signal = False
def handler(signum, frame):
global received_signal
received_signal = True
signal.signal(signal.SIGUSR1, handler)
while True:
time.sleep(1)
print("waiting for signal")
print(str(os.getpid()))
if received_signal:
received_signal = False
print('signal received')
send:
import os
import signal
with open("processid.txt","r") as pidinfo:
PID = int(pidinfo.read())
print(PID)
os.kill(PID, signal.SIGUSR1)
If these could also be improved upon in anyway I'd appreciate any tips