Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #77781 > unrolled thread

Re: Thread-ID - how much could be?

Started byPeter Otten <__peter__@web.de>
First post2014-09-12 00:02 +0200
Last post2014-09-12 00:02 +0200
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Thread-ID - how much could be? Peter Otten <__peter__@web.de> - 2014-09-12 00:02 +0200

#77781 — Re: Thread-ID - how much could be?

FromPeter Otten <__peter__@web.de>
Date2014-09-12 00:02 +0200
SubjectRe: Thread-ID - how much could be?
Message-ID<mailman.13945.1410472988.18130.python-list@python.org>
Ervin Hegedüs wrote:

> Hi Peter,
> 
> thanks for the reply,
> 
> On Thu, Sep 11, 2014 at 09:48:18PM +0200, Peter Otten wrote:
>> Ervin Hegedüs wrote:
>> 
>> > Exception in thread Thread-82:
>> > ...
>> > 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 threading.py 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 ;)
> 
> thanks - I hope that the memory will not run out by these
> threads... :)
> 
> Anyway, that means, on my system:
> 
>>>> import sys
>>>> print sys.maxint
> 9223372036854775807
> 
> the couter could be 9223372036854775807?
> 
> And after? :)

Try it!

>>> print sys.maxint + 1
9223372036854775808

When you start one thread per second

>>> sys.maxint / (60*60 * 24 * 365.25)
292271023045.3132

after less than 300 billion years the only thing that will change is the 
type:

>>> type(sys.maxint)
<type 'int'>
>>> type(sys.maxint + 1)
<type 'long'>

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web