• Home
  • Raw
  • Download

Lines Matching full:thread

1 :mod:`threading` --- Thread-based parallelism
5 :synopsis: Thread-based parallelism.
27 <global interpreter lock>`, only one thread
42 Return the number of :class:`Thread` objects currently alive. The returned
50 Return the current :class:`Thread` object, corresponding to the caller's thread
51 of control. If the caller's thread of control was not created through the
52 :mod:`threading` module, a dummy thread object with limited functionality is
60 Handle uncaught exception raised by :func:`Thread.run`.
67 * *thread*: Thread which raised the exception, can be ``None``.
76 exceptions raised by :func:`Thread.run` are handled.
82 Storing *thread* using a custom hook can resurrect it if it is set to an
83 object which is being finalized. Avoid storing *thread* after the custom
101 Return the 'thread identifier' of the current thread. This is a nonzero
103 to be used e.g. to index a dictionary of thread-specific data. Thread
104 identifiers may be recycled when a thread exits and another thread is
112 Return the native integral Thread ID of the current thread assigned by the kernel.
114 Its value may be used to uniquely identify this particular thread system-wide
115 (until the thread terminates, after which the value may be recycled by the OS).
124 Return a list of all :class:`Thread` objects currently active. The list
125 includes daemonic threads and dummy thread objects created by
127 that have not yet been started. However, the main thread is always part
133 Return the main :class:`Thread` object. In normal conditions, the
134 main thread is the thread from which the Python interpreter was
145 The *func* will be passed to :func:`sys.settrace` for each thread, before its
146 :meth:`~Thread.run` method is called.
165 The *func* will be passed to :func:`sys.setprofile` for each thread, before its
166 :meth:`~Thread.run` method is called.
180 Return the thread stack size used when creating new threads. The optional
184 0 is used. If changing the thread stack size is
215 they are separate objects in Python. Python's :class:`Thread` class supports a
216 subset of the behavior of Java's Thread class; currently, there are no
217 priorities, no thread groups, and threads cannot be destroyed, stopped,
218 suspended, resumed, or interrupted. The static methods of Java's Thread class,
224 Thread-Local Data
227 Thread-local data is data whose values are thread specific. To manage
228 thread-local data, just create an instance of :class:`local` (or a
239 A class that represents thread-local data.
247 Thread Objects
250 The :class:`Thread` class represents an activity that is run in a separate
251 thread of control. There are two ways to specify the activity: by passing a
252 callable object to the constructor, or by overriding the :meth:`~Thread.run`
255 :meth:`~Thread.__init__` and :meth:`~Thread.run` methods of this class.
257 Once a thread object is created, its activity must be started by calling the
258 thread's :meth:`~Thread.start` method. This invokes the :meth:`~Thread.run`
259 method in a separate thread of control.
261 Once the thread's activity is started, the thread is considered 'alive'. It
262 stops being alive when its :meth:`~Thread.run` method terminates -- either
263 normally, or by raising an unhandled exception. The :meth:`~Thread.is_alive`
264 method tests whether the thread is alive.
266 Other threads can call a thread's :meth:`~Thread.join` method. This blocks
267 the calling thread until the thread whose :meth:`~Thread.join` method is
270 A thread has a name. The name can be passed to the constructor, and read or
271 changed through the :attr:`~Thread.name` attribute.
273 If the :meth:`~Thread.run` method raises an exception,
277 A thread can be flagged as a "daemon thread". The significance of this flag is
279 initial value is inherited from the creating thread. The flag can be set
280 through the :attr:`~Thread.daemon` property or the *daemon* constructor
289 There is a "main thread" object; this corresponds to the initial thread of
290 control in the Python program. It is not a daemon thread.
292 There is the possibility that "dummy thread objects" are created. These are
293 thread objects corresponding to "alien threads", which are threads of control
295 thread objects have limited functionality; they are always considered alive and
296 daemonic, and cannot be :meth:`~Thread.join`\ ed. They are never deleted,
300 .. class:: Thread(group=None, target=None, name=None, args=(), kwargs={}, *, \
312 *name* is the thread name. By default, a unique name is constructed
313 of the form "Thread-*N*" where *N* is a small decimal number,
314 or "Thread-*N* (target)" where "target" is ``target.__name__`` if the
322 If not ``None``, *daemon* explicitly sets whether the thread is daemonic.
324 current thread.
327 base class constructor (``Thread.__init__()``) before doing anything else to
328 the thread.
338 Start the thread's activity.
340 It must be called at most once per thread object. It arranges for the
341 object's :meth:`~Thread.run` method to be invoked in a separate thread
345 on the same thread object.
349 Method representing the thread's activity.
358 Wait until the thread terminates. This blocks the calling thread until
359 the thread whose :meth:`~Thread.join` method is called terminates -- either
365 (or fractions thereof). As :meth:`~Thread.join` always returns ``None``,
366 you must call :meth:`~Thread.is_alive` after :meth:`~Thread.join` to
367 decide whether a timeout happened -- if the thread is still alive, the
368 :meth:`~Thread.join` call timed out.
371 block until the thread terminates.
373 A thread can be :meth:`~Thread.join`\ ed many times.
375 :meth:`~Thread.join` raises a :exc:`RuntimeError` if an attempt is made
376 to join the current thread as that would cause a deadlock. It is also
377 an error to :meth:`~Thread.join` a thread before it has been started
389 Deprecated getter/setter API for :attr:`~Thread.name`; use it directly as a
396 The 'thread identifier' of this thread or ``None`` if the thread has not
398 function. Thread identifiers may be recycled when a thread exits and
399 another thread is created. The identifier is available even after the
400 thread has exited.
404 The Thread ID (``TID``) of this thread, as assigned by the OS (kernel).
405 This is a non-negative integer, or ``None`` if the thread has not
407 This value may be used to uniquely identify this particular thread
408 system-wide (until the thread terminates, after which the value
413 Similar to Process IDs, Thread IDs are only valid (guaranteed unique
414 system-wide) from the time the thread is created until the thread
423 Return whether the thread is alive.
425 This method returns ``True`` just before the :meth:`~Thread.run` method
426 starts until just after the :meth:`~Thread.run` method terminates. The
431 A boolean value indicating whether this thread is a daemon thread (True)
432 or not (False). This must be set before :meth:`~Thread.start` is called,
434 from the creating thread; the main thread is not a daemon thread and
435 therefore all threads created in the main thread default to
436 :attr:`~Thread.daemon` = ``False``.
443 Deprecated getter/setter API for :attr:`~Thread.daemon`; use it directly as a
455 particular thread when locked. In Python, it is currently the lowest level
464 thread changes it to unlocked, then the :meth:`~Lock.acquire` call resets it
472 When more than one thread is blocked in :meth:`~Lock.acquire` waiting for the
473 state to turn to unlocked, only one thread proceeds when a :meth:`~Lock.release`
482 The class implementing primitive lock objects. Once a thread has acquired a
484 thread may release it.
521 Release a lock. This can be called from any thread, not only the thread
544 times by the same thread. Internally, it uses the concepts of "owning thread"
546 locks. In the locked state, some thread owns the lock; in the unlocked state,
547 no thread owns it.
549 To lock the lock, a thread calls its :meth:`~RLock.acquire` method; this
550 returns once the thread owns the lock. To unlock the lock, a thread calls
554 allows another thread blocked in :meth:`~Lock.acquire` to proceed.
562 released by the thread that acquired it. Once a thread has acquired a
563 reentrant lock, the same thread may acquire it again without blocking; the
564 thread must release it once for each time it has acquired it.
575 When invoked without arguments: if this thread already owns the lock, increment
577 thread owns the lock, block until the lock is unlocked. Once the lock is
578 unlocked (not owned by any thread), then grab ownership, set the recursion level
579 to one, and return. If more than one thread is blocked waiting until the lock
602 zero, reset the lock to unlocked (not owned by any thread), and if any other
605 nonzero, the lock remains locked and owned by the calling thread.
607 Only call this method when the calling thread owns the lock. A
632 another thread awakens it by calling :meth:`~Condition.notify` or
641 don't release the lock; this means that the thread or threads awakened will
643 the thread that called :meth:`~Condition.notify` or :meth:`~Condition.notify_all`
681 item to the buffer only needs to wake up one consumer thread.
687 allows one or more threads to wait until they are notified by another thread.
708 Wait until notified or until a timeout occurs. If the calling thread has
714 condition variable in another thread, or until the optional timeout
760 By default, wake up one thread waiting on this condition, if any. If the
761 calling thread has not acquired the lock when this method is called, a
772 Note: an awakened thread does not actually return from its :meth:`wait`
780 calling thread has not acquired the lock when this method is called, a
799 finds that it is zero, it blocks, waiting until some other thread calls
831 thread will be awoken by each call to :meth:`~Semaphore.release`. The
875 main thread would initialize the semaphore::
901 thread signals an event and other threads wait for it.
939 entry, return immediately. Otherwise, block until another thread calls
961 of time has passed --- a timer. :class:`Timer` is a subclass of :class:`Thread`
1008 As an example, here is a simple way to synchronize a client and server thread::
1041 for each thread. This can be used to select a thread to do some special
1046 # Only one thread needs to print this
1056 barrier is broken or reset while a thread is waiting.