[New-bugs-announce] [issue32244] Multiprocessing: multiprocessing.connection.Listener.accept() should accept a timeout

Tom Cook report at bugs.python.org
Thu Dec 7 10:09:59 EST 2017


New submission from Tom Cook <tom.k.cook at gmail.com>:

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.

----------
components: Library (Lib)
messages: 307809
nosy: Tom Cook
priority: normal
severity: normal
status: open
title: Multiprocessing: multiprocessing.connection.Listener.accept() should accept a timeout
type: enhancement
versions: Python 3.6

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32244>
_______________________________________


More information about the New-bugs-announce mailing list