我注意到我的Python程序创建了大量线程,在我启动脚本时会快速退出。我假设我使用的C扩展之一是创建线程,尽管我还使用multiprocessing
启动了一个额外的python进程。有没有一种简单的方法可以确定哪个扩展正在进行,或者是否有其它东西正在产生线程?
使用gdb,我看到了:
Starting program: /usr/bin/python ../myscript.py
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7fffee4be700 (LWP 29041)]
[New Thread 0x7fffedcbd700 (LWP 29042)]
[New Thread 0x7fffeb4bc700 (LWP 29043)]
[New Thread 0x7fffe8cbb700 (LWP 29044)]
[New Thread 0x7fffe64ba700 (LWP 29045)]
[New Thread 0x7fffe3cb9700 (LWP 29046)]
[New Thread 0x7fffe14b8700 (LWP 29047)]
[New Thread 0x7fffdecb7700 (LWP 29048)]
[New Thread 0x7fffdc4b6700 (LWP 29049)]
[New Thread 0x7fffd9cb5700 (LWP 29050)]
[New Thread 0x7fffd74b4700 (LWP 29051)]
[New Thread 0x7fffd4cb3700 (LWP 29052)]
[New Thread 0x7fffd24b2700 (LWP 29053)]
[New Thread 0x7fffcfcb1700 (LWP 29054)]
[New Thread 0x7fffcd4b0700 (LWP 29055)]
[New Thread 0x7fffcacaf700 (LWP 29056)]
[New Thread 0x7fffc84ae700 (LWP 29057)]
[New Thread 0x7fffc5cad700 (LWP 29058)]
[New Thread 0x7fffc34ac700 (LWP 29059)]
[New Thread 0x7fffc0cab700 (LWP 29060)]
[New Thread 0x7fffbe4aa700 (LWP 29061)]
[New Thread 0x7fffbbca9700 (LWP 29062)]
[New Thread 0x7fffb94a8700 (LWP 29063)]
[Thread 0x7fffc5cad700 (LWP 29058) exited]
[Thread 0x7fffb94a8700 (LWP 29063) exited]
[Thread 0x7fffe3cb9700 (LWP 29046) exited]
[Thread 0x7fffbbca9700 (LWP 29062) exited]
[Thread 0x7fffe8cbb700 (LWP 29044) exited]
[Thread 0x7fffbe4aa700 (LWP 29061) exited]
[Thread 0x7fffdecb7700 (LWP 29048) exited]
[Thread 0x7fffc0cab700 (LWP 29060) exited]
[Thread 0x7fffee4be700 (LWP 29041) exited]
[Thread 0x7fffc34ac700 (LWP 29059) exited]
[Thread 0x7fffd74b4700 (LWP 29051) exited]
[Thread 0x7fffc84ae700 (LWP 29057) exited]
[Thread 0x7fffcfcb1700 (LWP 29054) exited]
[Thread 0x7fffe14b8700 (LWP 29047) exited]
[Thread 0x7fffe64ba700 (LWP 29045) exited]
[Thread 0x7fffcacaf700 (LWP 29056) exited]
[Thread 0x7fffedcbd700 (LWP 29042) exited]
[Thread 0x7fffcd4b0700 (LWP 29055) exited]
[Thread 0x7fffdc4b6700 (LWP 29049) exited]
[Thread 0x7fffd24b2700 (LWP 29053) exited]
[Thread 0x7fffd4cb3700 (LWP 29052) exited]
[Thread 0x7fffeb4bc700 (LWP 29043) exited]
[Thread 0x7fffd9cb5700 (LWP 29050) exited]
20150201 22:13:27.896983 - INFO - myscript.py:517 - Begin logging
[New Thread 0x7fffb94a8700 (LWP 29070)]
[New Thread 0x7fffbbca9700 (LWP 29071)]
答案 0 :(得分:0)
也许尝试崩溃线程并检查堆栈跟踪。如果没有代码,几乎无法提供更多帮助
答案 1 :(得分:0)
使用gdb breakpoint on pthread_create我发现创建所有线程的是libblas。将OMP_NUM_THREADS
设置为1可以解决问题。