-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 08/12/2013 04:35 AM, Antoine Pitrou wrote:
> Le Fri, 9 Aug 2013 21:20:01 -0400, Alex Riina <[email protected]> a
> écrit :
>> I'd like to start migrating processes over to use supervisor, but
>> I'm hoping for a little more control over the processes that I have
>> found so far. Is there a canonical way to handling "soft restarts"
>> or tear downs in supervisor processes? For example, if I have a
>> process like:
>>
>> setup_logic() while True: run_logic()
>>
>> Is there a recommended way to schedule a restart of the process
>> without interrupting the current loop? Is there a way to add a
>> teardown hook to the process?
>
> AFAICT, a common way to handle soft restarts (aka "reloads") of a
> daemon is to send it a SIGHUP (and for the daemon to intercept the
> signal, of course).
SIGHUP is often used for "reload configuration" (or sometimes "reopen log
files") rather than "stop gracefully", which is what SIGTERM normally
means. Whichever signal you use, the best practice would be to have the
signal handler do only a single, atomic operation. E.g., for the case
above, set a sentinel which controls the loop::
import signal
terminated = []
def _terminate(signum, *ignored):
terminated.append(signum)
signal.signal(signal.SIGTERM, _terminate)
setup_logic()
while not terminated:
run_logic()
do_cleanup()
>> For the second question, I'm currently registering my teardown via
>> signal.signal(signal.SIGTERM, teardown), but I feel like both must
>> be such common questions that better solutions must exist.
>
> I'm afraid not :-)
The stdlib 'atexit' module might be what you need, depending. I wouldn't
do any heavy-duty cleanup in the actual signal handler itself, especially
if your daemon uses threads.
Tres.
- --
===================================================================
Tres Seaver +1 540-429-0999 [email protected]
Palladion Software "Excellence by Design" http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with undefined - http://www.enigmail.net/
iEYEARECAAYFAlII0/cACgkQ+gerLs4ltQ4LegCePof5CJ8rloVaYAX96XlHolDE
KJUAn21YW94obp5tnAhKP687EP0rf1UL
=SJ1t
-----END PGP SIGNATURE-----
_______________________________________________
Supervisor-users mailing list
[email protected]
https://lists.supervisord.org/mailman/listinfo/supervisor-users