調試python的“錯誤:不能啟動新線程”

[英]debugging python's “error: can't start new thread”


Rarely I receive the following error:

我很少收到以下錯誤:

Exception in thread Thread-1240:
Traceback (most recent call last):
  File "C:\Python26\lib\threading.py", line 534, in __bootstrap_inner
    self.run()
  File "C:\Python26\lib\threading.py", line 738, in run
    self.function(*self.args, **self.kwargs)
  File "C:\Users\MyUser\Documents\MyProject\a_script.py", line 33, in some_func
    t.start()
  File "C:\Python26\lib\threading.py", line 476, in start
    _start_new_thread(self.__bootstrap, ())
error: can't start new thread

From here I gather I've hit some resource limit related to having too many threads in the same process. t.start() (that line 33 above) starts a Timer object which indeed opens a new thread, however, my architecture is such that no more than a few timers should exist simultaneously.

從這里開始,我估計我遇到了一些資源限制,這與同一進程中有太多線程有關。t.start()(上面第33行)啟動一個計時器對象,它確實打開了一個新的線程,但是,我的體系結構是,不應該同時存在超過幾個計時器。

As this a rare event and I do not know how to recreate it, I would like to set it so that next time it happens I'll have all the info I need. This doesn't seem like a regular Python exception (no exception type specified...). Is it possible to try-except it? Are there alternatives to catching what's going on beyond try-catch?

由於這是一個罕見的事件,我不知道如何重新創建它,我想設置它,以便下次它發生時,我將擁有所有我需要的信息。這看起來不像是一個常規的Python異常(沒有指定異常類型…)。可以試戴嗎?有沒有其他的辦法去捕捉除了嘗試之外的事情?

1 个解决方案

#1


3  

It is a normal exception, actually it's thread.error ("thread" is the module which does all the low-level stuff). It's aliased in the "threading" module as ThreadError, so just catch threading.ThreadError.

這是一個正常的例外,實際上是線程。錯誤(“thread”是做所有低級工作的模塊)。它在“線程”模塊中別名為ThreadError,因此只需捕獲thread .ThreadError。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2011/06/30/7129d28abf2f4d2d689e23dc3a9ed1bb.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com