My program appears to run in a deadlock sometimes when I hit Ctrl+C. I'm trying to catch the keyboard interrupt and gracefully stop all running threads, but I'm not quite there yet.
I'm using a concurrent.futures.ThreadPoolExecutor
. To find the location of the deadlock, I'm using the this receipe from ActiveState.
Now, here's the full stacktrace:
# ThreadID: 4856
File: "c:\users\niklas\appdata\local\programs\python\python36\lib\threading.py", line 884, in _bootstrap
self._bootstrap_inner()
File: "c:\users\niklas\appdata\local\programs\python\python36\lib\threading.py", line 916, in _bootstrap_inner
self.run()
File: "C:\Users\niklas\repos\nodepy\craftr\lib\utils\tracer.py", line 66, in run
self.stacktraces()
File: "C:\Users\niklas\repos\nodepy\craftr\lib\utils\tracer.py", line 80, in stacktraces
fout.write(stacktraces())
File: "C:\Users\niklas\repos\nodepy\craftr\lib\utils\tracer.py", line 28, in stacktraces
for filename, lineno, name, line in traceback.extract_stack(stack):
# ThreadID: 6068
File: "c:\users\niklas\appdata\local\programs\python\python36\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File: "c:\users\niklas\appdata\local\programs\python\python36\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File: "C:\Users\niklas\repos\nodepy\craftr\.nodepy_modules\.bin\craftr.exe\__main__.py", line 9, in <module>
sys.exit(nodepy.main.main())
File: "c:\users\niklas\repos\nodepy\nodepy\nodepy\main.py", line 103, in main
ctx.load_module(ctx.main_module, do_init=False)
File: "c:\users\niklas\repos\nodepy\nodepy\nodepy\context.py", line 253, in load_module
module.load()
File: "c:\users\niklas\repos\nodepy\nodepy\nodepy\loader.py", line 43, in load
exec(code, vars(self.namespace))
File: "C:\Users\niklas\repos\nodepy\craftr\lib\main.py", line 110, in <module>
sys.exit(main())
File: "C:\Users\niklas\repos\nodepy\craftr\lib\main.py", line 106, in main
return backend.build_main(backend_args, session, module)
File: "C:\Users\niklas\repos\nodepy\craftr\lib\build_backends\default.py", line 194, in build_main
executor.run(actions)
File: "C:\Users\niklas\repos\nodepy\craftr\lib\build_backends\default.py", line 171, in run
self.wait()
File: "C:\Users\niklas\repos\nodepy\craftr\lib\build_backends\default.py", line 137, in wait
self.pool.shutdown(wait=True)
File: "c:\users\niklas\appdata\local\programs\python\python36\lib\concurrent\futures\thread.py", line 144, in shutdown
t.join()
File: "c:\users\niklas\appdata\local\programs\python\python36\lib\threading.py", line 1056, in join
self._wait_for_tstate_lock()
File: "c:\users\niklas\appdata\local\programs\python\python36\lib\threading.py", line 1072, in _wait_for_tstate_lock
elif lock.acquire(block, timeout):
I can't make sense from this traceback. It appears that Thread._wait_for_tstate_lock()
never returns (I checked multiple times, it always hangs at that line). There is no thread running other than the main thread (6068) and the tracer thread (4856).
I don't quite understand the implementation details of threading.Thread
. What could cause Thread._tstate_lock.acquire()
to block indefinitely?
Update 2017/11/07 -- 01:45am CEWT
This seems to happen when pool.shutdown()
is called multiple times...