• Home
  • Raw
  • Download

Lines Matching full:thread

1 """Thread module emulating a subset of Java's threading model."""
6 import thread
32 'Lock', 'RLock', 'Semaphore', 'BoundedSemaphore', 'Thread',
35 _start_new_thread = thread.start_new_thread
36 _allocate_lock = thread.allocate_lock
37 _get_ident = thread.get_ident
38 ThreadError = thread.error
39 del thread
73 name = "<OS thread %d>" % ident
93 The func will be passed to sys.setprofile() for each thread, before its
103 The func will be passed to sys.settrace() for each thread, before its run()
117 A reentrant lock must be released by the thread that acquired it. Once a
118 thread has acquired a reentrant lock, the same thread may acquire it again
119 without blocking; the thread must release it once for each time it has
126 """A reentrant lock must be released by the thread that acquired it. Once a
127 thread has acquired a reentrant lock, the same thread may acquire it
128 again without blocking; the thread must release it once for each time it
150 When invoked without arguments: if this thread already owns the lock,
152 if another thread owns the lock, block until the lock is unlocked. Once
153 the lock is unlocked (not owned by any thread), then grab ownership, set
154 the recursion level to one, and return. If more than one thread is
191 by any thread), and if any other threads are blocked waiting for the
194 locked and owned by the calling thread.
196 Only call this method when the calling thread owns the lock. A
246 notified by another thread.
257 notified by another thread.
312 If the calling thread has not acquired the lock when this method is
317 variable in another thread, or until the optional timeout occurs. Once
376 If the calling thread has not acquired the lock when this method is
403 If the calling thread has not acquired the lock when this method
445 on entry, block, waiting until some other thread has called release() to
482 When the counter is zero on entry and another thread is waiting for it
483 to become larger than zero again, wake up that thread.
528 When the counter is zero on entry and another thread is waiting for it
529 to become larger than zero again, wake up that thread.
567 # private! called by Thread._reset_internal_locks by _after_fork()
601 block until another thread calls set() to set the flag to true, or until
617 # Helper to generate new thread names
619 _counter() # Consume 0 so first non-main thread has id 1.
620 def _newname(template="Thread-%d"):
623 # Active thread administration
625 _active = {} # maps thread id to Thread object
631 class Thread(_Verbose): class
632 """A class that represents a thread of control.
639 # out exceptions when a thread tries to use a global var. during interp.
657 *name* is the thread name. By default, a unique name is constructed of
658 the form "Thread-N" where N is a small decimal number.
666 the base class constructor (Thread.__init__()) before doing anything
667 else to the thread.
705 assert self.__initialized, "Thread.__init__() was not called"
718 """Start the thread's activity.
720 It must be called at most once per thread object. It arranges for the
721 object's run() method to be invoked in a separate thread of control.
724 same thread object.
728 raise RuntimeError("thread.__init__() not called")
732 self._note("%s.start(): starting thread", self)
744 """Method representing the thread's activity.
756 # Avoid a refcycle if the thread is running a function with
757 # an argument that has a member that points to the thread.
763 # happen when a daemon thread wakes up at an unfortunate
791 self._note("%s.__bootstrap(): thread started", self)
813 print>>_sys.stderr, ("Exception in thread %s:\n%s" %
822 "Exception in thread " + self.name +
868 "Remove current thread from the dict of currently running threads."
875 # there is only one thread if dummy_thread is being used. Thus
876 # len(_active) is always <= 1 here, and any Thread instance created
877 # overwrites the (if any) thread currently registered in _active.
880 # gets overwritten the instant an instance of Thread is created; both
884 # it gets a KeyError if another Thread instance was created.
896 # could try to acquire the lock again in the same thread, (in
903 """Wait until the thread terminates.
905 This blocks the calling thread until the thread whose join() method is
913 thread is still alive, the join() call timed out.
916 block until the thread terminates.
918 A thread can be join()ed many times.
921 thread as that would cause a deadlock. It is also an error to join() a
922 thread before it has been started and attempts to do so raises the same
927 raise RuntimeError("Thread.__init__() not called")
929 raise RuntimeError("cannot join thread before it is started")
931 raise RuntimeError("cannot join current thread")
935 self._note("%s.join(): waiting until thread stops", self)
942 self._note("%s.join(): thread stopped", self)
954 self._note("%s.join(): thread stopped", self)
966 assert self.__initialized, "Thread.__init__() not called"
971 assert self.__initialized, "Thread.__init__() not called"
976 """Thread identifier of this thread or None if it has not been started.
978 This is a nonzero integer. See the thread.get_ident() function. Thread
979 identifiers may be recycled when a thread exits and another thread is
980 created. The identifier is available even after the thread has exited.
983 assert self.__initialized, "Thread.__init__() not called"
987 """Return whether the thread is alive.
994 assert self.__initialized, "Thread.__init__() not called"
1001 """A boolean value indicating whether this thread is a daemon thread (True) or not (False).
1004 raised. Its initial value is inherited from the creating thread; the
1005 main thread is not a daemon thread and therefore all threads created in
1006 the main thread default to daemon = False.
1012 assert self.__initialized, "Thread.__init__() not called"
1018 raise RuntimeError("Thread.__init__() not called")
1020 raise RuntimeError("cannot set daemon status of active thread");
1049 class _Timer(Thread):
1059 Thread.__init__(self)
1076 # Special thread class to represent the main thread
1079 class _MainThread(Thread):
1082 Thread.__init__(self, name="MainThread")
1111 # Dummy thread class to represent threads not started here.
1119 class _DummyThread(Thread):
1122 Thread.__init__(self, name=_newname("Dummy-%d"))
1124 # Thread.__block consumes an OS-level locking primitive, which
1138 assert False, "cannot join a dummy thread"
1144 """Return the current Thread object, corresponding to the caller's thread of control.
1146 If the caller's thread of control was not created through the threading
1147 module, a dummy thread object with limited functionality is returned.
1153 ##print "current_thread(): no current thread for", _get_ident()
1159 """Return the number of Thread objects currently alive.
1175 """Return a list of all Thread objects currently alive.
1177 The list includes daemonic threads, dummy thread objects created by
1178 current_thread(), and the main thread. It excludes terminated threads and
1185 from thread import stack_size
1187 # Create the main thread object,
1193 # get thread-local implementation, either from the thread
1197 from thread import _local as local
1208 # by another (non-forked) thread. http://bugs.python.org/issue874900
1212 # fork() only copied the current thread; clear references to others.
1216 for thread in _enumerate():
1219 if hasattr(thread, '_reset_internal_locks'):
1220 thread._reset_internal_locks()
1221 if thread is current:
1222 # There is only one active thread. We reset the ident to
1225 thread._Thread__ident = ident
1226 new_active[ident] = thread
1229 thread._Thread__stop()
1273 class ProducerThread(Thread):
1276 Thread.__init__(self, name="Producer")
1289 class ConsumerThread(Thread):
1292 Thread.__init__(self, name="Consumer")