Page MenuHomePhabricator

fix sdwdate sigterm handling during get_time_from_servers
Open, NormalPublic


When sdwdate is inside the threads loop in function get_time_from_servers from file, signal sigterm does not lead to sdwdate terminating.

signal_sigterm_handler is triggered, but sys.exit(143) is without effect.

Apparently that is to be expected.


  • Shut terminate all eventually running threads and exit.

How to reproduce?

set -x

cd ~/Whonix/packages/sdwdate
sudo make install
sudo -u sdwdate sdwdate &


sleep 1

sudo kill -sigterm "$sdwdate_pid"

wait "$sdwdate_pid"
true $?

The signal must send during.

Requested urls ['x.onion', 'y.onion', 'z.onion']

I.e. signal must send during gevent.wait().



Event Timeline by @joysn1980 helped a lot. Showed be the correct place where to implement this.

Maybe not the cleanest implementation. Help welcome.

Can we call /usr/bin/sdwdate's exit_handler() directly from

A python coding question. These two code blocks.

My implementation is a bit weird. Can we call /usr/bin/sdwdate's exit_handler() directly from @marmarek

Where the other thread is created? For me it looks like get_time_from_servers is running in the main thread, so simply not catching SystemExit should be enough. At the point where it was raised, you already called sys.exit (which is how SystemExit is raised), so exit_handler was already called.

If I'm mistaken about this, and it's running in non-main thread, you may want to use instead, and check it in main loop. Something like:

exit_event = threading.Event()


if exit_event.is_set():

And from the other thread:


Also, Python >= 3.4 comes with great API for concurrent execution - asyncio - much more powerful version of asyncore. In this case it could be used to avoid threads at all. But I'm still learning how to use it... You may want to read/watch this: if you want quick intro.