Skip to content

Fix problem with cleanup, when TestTools were used out of pytest

(If you don't know what "daemon" means in threading context, stop here and learn about it first).

Problem was noticed during running script, which generates block log for tests in HAF (haf/tests/integration/local_tools/generate_block_log.py). When main thread was completed, cleanup was not triggered. So everything hung, because notification servers were still running.

I registered cleanup triggerring with atexit package. It turned out, that my handler are not run at the end of main thread. It will be run, when all other non-daemon threads will be closed. But their never will, because closing these servers were atexit's responsibility...

I found solution in this great article: https://superfastpython.com/stop-daemon-thread/

Now main thread is the only one non-daemon thread. So when it ends, all other threads will be closed. But before closing daemon threads Python will run our atexit handler, and will politely wait, until handler will finish. So now cleanup is run at the right moment and has time to perform.

Please review: @kmochocki @mzebrak
FYI: @msobczyk

Edited by Piotr Batko

Merge request reports