New submission from Tom Cook <tom.k.c...@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 <rep...@bugs.python.org>
<https://bugs.python.org/issue32244>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to