Shane
(Shane Harvey)
6
I can’t say without more info. Could you try calling dump_traceback when the operation hangs? Something like this where blocking_workload should be replaced with your hanging code:
import faulthandler
import threading
import time
def blocking_workload():
time.sleep(100)
def main():
thread = threading.Thread(target=blocking_workload)
thread.daemon = True # Set daemon to avoid blocking on exit.
thread.start()
# Print traceback of all threads on timeout.
thread.join(3)
if thread.is_alive():
faulthandler.dump_traceback()
if __name__ == "__main__":
main()
Running this script will produce output like this:
$ python print_threads_on_timeout.py
Thread 0x000000016c1ff000 (most recent call first):
File "/Users/shane/git/mongo-python-driver/fault.py", line 7 in blocking_workload
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/threading.py", line 989 in run
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/threading.py", line 1052 in _bootstrap_inner
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/threading.py", line 1009 in _bootstrap
Current thread 0x00000001ea598c00 (most recent call first):
File "/Users/shane/git/mongo-python-driver/fault.py", line 17 in main
File "/Users/shane/git/mongo-python-driver/fault.py", line 21 in <module>
This will show use where the hang is happening.