I've been trying to make a program that will allow multiple other programs to connect and send messages to a single port. The issue is that at some point, seemingly in the depths of the multiprocessing module, a call to os.read
hangs on both ends.
Demo receive.py
:
from multiprocessing.connection import Listener
while True:
with Listener(("localhost", 10000), authkey=b"test") as listener:
with listener.accept() as connection:
print(connection.recv())
Demo send.py
(sends 1000 times to mimic multiple programs and expose the problem):
from multiprocessing.connection import Client
for i in range(1000):
successfully_sent = False
while not successfully_sent:
try:
with Client(("localhost", 10000), authkey=b"test") as client:
client.send(i)
except (ConnectionRefusedError, ConnectionResetError):
continue
successfully_sent = True
Any hints on how to force the processes to continue without losing any messages would be appreciated. I've considered using threading in receive.py to force timeouts, but I'm hoping there's a cleaner way that addresses the underlying problem. Also, is this a bug?