开发者

debugging python's "error: can't start new thread"

开发者 https://www.devze.com 2023-03-16 23:26 出处:网络
Rarely I receive the following error: Exception in thread Thread-1240: Traceback (most recent call last):

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.

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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消