Visitar URL original
Thread name not a small integer, ever increasing, creating exception · Issue #114345 · python/cpython · GitHub
The Wayback Machine - https://web.archive.org/web/20251108051407/https://github.com/python/cpython/issues/114345
Skip to content

Thread name not a small integer, ever increasing, creating exception #114345

@aerilox

Description

@aerilox

Bug report

Bug description:

The subject had originally been covered here
The docu of threading.py says
"name is the thread name. By default, a unique name is constructed of the form “Thread-N” where N is a small decimal number, or “Thread-N (target)” where “target” is target.name if the target argument is specified."
N is not a small decimal number, it is ever increasing with every thread that is started. Also Timer threads are affected.

import time
tt=None
i=-1
st=time.time()
def test():
    global tt, i, st
    tt=threading.Timer(0.0, test)
    i+=1
    if i%100000==0:
        oldst=st
        st=time.time()
        print (tt.name, st-oldst )
    tt.start()

On a long-running daemon on Windows Server 2019 and Python 3.8 the code throws an exception passing through a number close to 16777216

Exception in thread Thread-16711544:
Traceback (most recent call last):
  File "C:\python38\lib\threading.py", line 932, in _bootstrap_inner
    self.run()
  File "C:\python38\lib\threading.py", line 1252, in run
    self.finished.wait(self.interval)
  File "C:\python38\lib\threading.py", line 558, in wait
    signaled = self._cond.wait(timeout)
  File "C:\python38\lib\threading.py", line 295, in wait
    waiter = _allocate_lock()
RuntimeError: can't allocate lock

The occurence can be solidely reproduced. Actual N varies for each occurence/exception +- a couple 100.
On a Win10/11 + Python 3.11 system the exception at that specific N range could not be observed.
Size of N and exception may not be related. Nevertheless it raises a concern about long-running daemons that may trespas some sort of integer barrier on N that could raise an exception after a very very long time. N should be limited to a small number/reused as written in the doc imo.

CPython versions tested on:

3.8

Operating systems tested on:

Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions