Commit bcd62ab0 authored by Michael Terry's avatar Michael Terry
Browse files

Exit spawned background task threads when extension closes

Previously, a spawned thread would stay open even after the GUI shut
down. Meaning a stuck thread (network issues maybe) would leave the
executable running indefinitely.

This turns threads created by "asyncme.py" helper functions into
daemonic threads, which are stopped at shutdown. This will be an
abrupt thread shutdown, but I believe that should be safe because
this async module is used for GUI helpers, and if the GUI has
exited... There is an escape valve you can use if you do need to
wait on a thread by just calling join() yourself before you exit.

Fixes #628
parent 81912dec
Loading
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -222,9 +222,12 @@ class DebouncedSyncVar:
def spawn_thread(func):
    """Call ``func()`` in a separate thread

    This spawned thread will exit when the main thread does.
    If you want to wait for the thread to exit, use join() on the returned thread.

    Returns the corresponding :class:`threading.Thread` object.
    """
    thread = threading.Thread(target=func)
    thread = threading.Thread(target=func, daemon=True)
    thread.start()
    return thread

@@ -294,7 +297,7 @@ def holding(lock, task, blocking=True):
            ret.wait()
        lock.release()

    threading.Thread(target=_target).start()
    spawn_thread(_target)
    return ret