Author Tom Cook
Recipients Tom Cook
Date 2017-12-07.15:09:59
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1512659399.52.0.213398074469.issue32244@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2017-12-07 15:09:59Tom Cooksetrecipients: + Tom Cook
2017-12-07 15:09:59Tom Cooksetmessageid: <1512659399.52.0.213398074469.issue32244@psf.upfronthosting.co.za>
2017-12-07 15:09:59Tom Cooklinkissue32244 messages
2017-12-07 15:09:59Tom Cookcreate