python-daemon interaction with multiprocessing (secure-smtpd)

Grant Edwards invalid at invalid.invalid
Wed May 7 15:11:37 EDT 2014


On 2014-05-07, Ben Finney <ben at benfinney.id.au> wrote:
> Grant Edwards <invalid at invalid.invalid> writes:
>
>> On 2014-05-07, Grant Edwards <invalid at invalid.invalid> wrote:
>> >     How do you terminate a Python program that's using multiprocessing?
>>
>> It looks like you have to kill all the threads individually.  :/
>
> As I understand it, the ‘multiprocessing’ module
><URL:https://docs.python.org/3/library/multiprocessing.html> does not
> create multiple threads; it creates multiple processes.

Right.  I should have written processes rather than threads.

> It also closely follows the API for the ‘threading’ module. That
> includes the ability to manage a pool of workers
><URL:https://docs.python.org/3/library/multiprocessing.html#module-multiprocessing.pool>.

Except when you kill the parent of a bunch of threads, they all get
killed.  That doesn't seem to be the case for multiprocessing.

> You can ask the pool of workers to close when they're done
><URL:https://docs.python.org/3/library/multiprocessing.html#multiprocessing.pool.Pool.close>.
> Does that address the requirement?

I'm not sure.  It's not really my code that's creating and managing
the pool: that's happening inside the secure-smtpd module from
https://github.com/bcoe/secure-smtpd.  There's a little bit of wrapper
code that configures the server and then starts it -- after that I
don't have much control over anything.

Mainly, I'm just trying to figure out the right way to terminate the
server from an /etc/init script.

-- 
Grant Edwards               grant.b.edwards        Yow! We're going to a
                                  at               new disco!
                              gmail.com            



More information about the Python-list mailing list