- 论坛徽章:
- 11
|
文档没说明thread name的生成规则,只有看代码了,截取一段Python 2.7的实现,可以解释你遇到的现象(
threading实现)
thread name的规则- 409 # Helper to generate new thread names
- 410 _counter = 0
- 411 def _newname(template="Thread-%d"):
- 412 global _counter
- 413 _counter = _counter + 1
- 414 return template % _counter
复制代码 thread构造函数- 422 # Main class for threads
- 423
- 424 class Thread(_Verbose):
- 425
- 426 __initialized = False
- 427 # Need to store a reference to sys.exc_info for printing
- 428 # out exceptions when a thread tries to use a global var. during interp.
- 429 # shutdown and thus raises an exception about trying to perform some
- 430 # operation on/with a NoneType
- 431 __exc_info = _sys.exc_info
- 432 # Keep sys.exc_clear too to clear the exception just before
- 433 # allowing .join() to return.
- 434 __exc_clear = _sys.exc_clear
- 435
- 436 def __init__(self, group=None, target=None, name=None,
- 437 args=(), kwargs=None, verbose=None):
- 438 assert group is None, "group argument must be None for now"
- 439 _Verbose.__init__(self, verbose)
- 440 if kwargs is None:
- 441 kwargs = {}
- 442 self.__target = target
- 443 self.__name = str(name or _newname())
复制代码 |
|