Thread-ID - how much could be?

Peter Otten __peter__ at
Thu Sep 11 21:48:18 CEST 2014

Ervin Hegedüs wrote:

> I've made a long-time running daemon, which uses threads. Looks
> like that works perfectly, now I'm looking at the exceptions :).
> In the log, I found an interesting message:
> Exception in thread Thread-82:
> ...
> The main function allows 2 thread to run simultaniously, and if
> the thread finished, then it joined with th.join(), where the
> "th" is the thread item, derived from threading.Thread class.
> My question is: how much thread ID could be totally? Is there any
> maximum number? And if the thread reached that, what will be
> done? Overlflowed? Couting from 0 again?

A quick peak into reveals

# Helper to generate new thread names
_counter = 0
def _newname(template="Thread-%d"):
    global _counter
    _counter += 1
    return template % _counter

class Thread:
    def __init__(self, group=None, target=None, name=None,
                 args=(), kwargs=None, *, daemon=None):
        self._name = str(name or _newname())

There is no upper limit to the thread name other than that you will 
eventually run out of memory ;)

More information about the Python-list mailing list