我有一个运行少量线程的python脚本。通常,当我想调试python脚本时,我用“-m pdb”运行它,然后用“b”设置一个断点。然而,由于某种原因它甚至不会在断点处停止,即使它通过该线,甚至我看到断点实际上已被添加。知道我做错了什么吗?我在here
中使用了一个简单的python线程模块示例import threading
class SummingThread(threading.Thread):
def __init__(self,low,high):
threading.Thread.__init__(self)
self.low=low
self.high=high
self.total=0
def run(self):
print 'self.low = ' + str(self.low) + ', self.high = ' + str(self.high)
for i in range(self.low,self.high):
self.total+=i
thread1 = SummingThread(0,500000)
thread2 = SummingThread(500000,1000000)
thread1.start() # This actually causes the thread to run
thread2.start()
thread1.join() # This waits until the thread has completed
thread2.join()
# At this point, both threads have completed
result = thread1.total + thread2.total
print result
然后我使用run
命令在print
方法的行内添加一个断点并运行脚本。脚本运行,通过print
命令,但不会停止。
~$ python -m pdb test.py
> /home/user/test.py(1)<module>()
-> import threading
(Pdb) b 11
Breakpoint 1 at /home/user/test.py:11
(Pdb) r
self.low = 0, self.high = 500000
self.low = 500000, self.high = 1000000
499999500000
--Return--
> /home/user/test.py(24)<module>()->None
-> print result
(Pdb) q