threading.activeCount (), which returns the number of active threads (which were started from this module). [Source] C>
Since the streaming module is a pure python module built on top of the stream module, it is fairly easy to view the source code.
Here is the source code for active_count
def activeCount():
"""Return the number of Thread objects currently alive.
The returned count is equal to the length of the list returned by
enumerate().
"""
with _active_limbo_lock:
return len(_active) + len(_limbo)
, _MainThread _active (_active _limbo - , ). _active _exitfunc.
_MainThread,
class _MainThread(Thread):
def __init__(self):
Thread.__init__(self, name="MainThread")
self._Thread__started.set()
self._set_ident()
with _active_limbo_lock:
_active[_get_ident()] = self
def _set_daemon(self):
return False
def _exitfunc(self):
self._Thread__stop()
t = _pickSomeNonDaemonThread()
if t:
if __debug__:
self._note("%s: waiting for other threads", self)
while t:
t.join()
t = _pickSomeNonDaemonThread()
if __debug__:
self._note("%s: exiting", self)
self._Thread__delete()
_exitfunc _MainThread , - , Thread._delete, mangled to __Thread_delete, , , _MainThread _active.
_exitfunc _shutdown 1201.
_shutdown = _MainThread()._exitfunc
_shutdown pythonrun.c, , , Py_Finalize. Py_Finalize Py_Exit, ( ).
Py_Exit.
. Py_Finalize(), C ().
, .
import threading, time
def f():
time.sleep(1)
print threading.enumerate()
if __name__ == '__main__':
t = threading.Thread(target=f)
t.daemon = True
t.start()
threading._shutdown()
, , .