threading module
Aahz Maruch
aahz at netcom.com
Tue Jun 27 10:07:30 EDT 2000
In article <3958265D.906DECF5 at yahoo.com>,
Al-Amerrho H. Amerin <al_amerin at yahoo.com> wrote:
>
>I was using the threading module's activeCount() method when I noticed
>that when you import it, it spawns a thread, MainThread. And this
>becomes a problem when I call threading.activeCount(). It returns the
>number of threads I spawned + 1.
Nope, it doesn't spawn a thread. That thread existed when you started
Python; what threading does is *register* that thread with itself.
>Python 1.6a2 (#9, Jun 22 2000, 00:09:08) [GCC 2.95.2 19991024
>(release)] on linux2
>Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>Copyright 1995-2000 Corporation for National Research Initiatives (CNRI)
>
>>>> import threading
>>>> threading.activeCount()
>1
>>>>
>
>I hope someone can enlighten me as to the reason why activeCount()
>includes the MainThread and why this shouldn't be fixed so
>activeCount() will only return the number of threads that a caller
>spawns.
Because the main thread is a thread just as much as any other thread.
For example, you could exit the main thread and your other threads would
continue running.
--
--- Aahz (Copyright 2000 by aahz at netcom.com)
Androgynous poly kinky vanilla queer het <*> http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6
The best way to get information on Usenet is not to ask a question,
but to post the wrong information. --Aahz
More information about the Python-list
mailing list