Issue 32244: Multiprocessing: multiprocessing.connection.Listener.accept() should accept a timeout (original) (raw)
Issue32244
Created on 2017-12-07 15:09 by Tom Cook, last changed 2022-04-11 14:58 by admin.
Messages (3) | ||
---|---|---|
msg307809 - (view) | Author: Tom Cook (Tom Cook) | Date: 2017-12-07 15:09 |
If nothing connects to it, `multiprocessing.connection.Listener.accept()` will block forever with no good way to interrupt it. Supposing that a thread implements a loop like this: def run(self): l = Listener(socket_path, 'AF_UNIX') while self.running: c = l.accept() while self.running: data = c.recv() self.process(data) There is no obvious way to implement a `stop` method on this thread. Setting `self.running = False` may never result in the thread terminating, as it may be that no client connects to it. The following is a possible way of implementing it: def stop(self): self.running = False try: c = Client(socket_path, 'AF_UNIX') except: pass however it seems fraught with race conditions. Letting `accept()` accept a timeout would be a much cleaner solution to this and many similar problems. | ||
msg307810 - (view) | Author: Tom Cook (Tom Cook) | Date: 2017-12-07 15:12 |
The same goes for `Connection.recv()`, as in the sample code another case where the thread will never terminate is when a `Client` is connected to the socket but never sends any messages; in this case, the call to `recv()` will block forever. There is no way at all to interrupt this. | ||
msg378675 - (view) | Author: Carlo Dri (carlodri) * | Date: 2020-10-15 11:18 |
In agree with this proposal! I was looking for the exact same possibility of specifying a timeout to the accept() method, both in AF_INET and AF_PIPE sockets. If there is any better way to implement this I would love to hear it. |
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-04-11 14:58:55 | admin | set | github: 76425 |
2020-10-15 11:21:51 | carlodri | set | versions: + Python 3.8 |
2020-10-15 11🔞26 | carlodri | set | nosy: + carlodrimessages: + |
2017-12-07 15:12:45 | Tom Cook | set | messages: + |
2017-12-07 15:09:59 | Tom Cook | create |