• Home
  • Raw
  • Download

Lines Matching full:thread

1 :mod:`threading` --- Thread-based parallelism
5 :synopsis: Thread-based parallelism.
29 Return the number of :class:`Thread` objects currently alive. The returned
35 Return the current :class:`Thread` object, corresponding to the caller's thread
36 of control. If the caller's thread of control was not created through the
37 :mod:`threading` module, a dummy thread object with limited functionality is
43 Return the 'thread identifier' of the current thread. This is a nonzero
45 to be used e.g. to index a dictionary of thread-specific data. Thread
46 identifiers may be recycled when a thread exits and another thread is
54 Return a list of all :class:`Thread` objects currently alive. The list
55 includes daemonic threads, dummy thread objects created by
56 :func:`current_thread`, and the main thread. It excludes terminated threads
62 Return the main :class:`Thread` object. In normal conditions, the
63 main thread is the thread from which the Python interpreter was
74 The *func* will be passed to :func:`sys.settrace` for each thread, before its
75 :meth:`~Thread.run` method is called.
83 The *func* will be passed to :func:`sys.setprofile` for each thread, before its
84 :meth:`~Thread.run` method is called.
89 Return the thread stack size used when creating new threads. The optional
93 0 is used. If changing the thread stack size is
124 they are separate objects in Python. Python's :class:`Thread` class supports a
125 subset of the behavior of Java's Thread class; currently, there are no
126 priorities, no thread groups, and threads cannot be destroyed, stopped,
127 suspended, resumed, or interrupted. The static methods of Java's Thread class,
133 Thread-Local Data
136 Thread-local data is data whose values are thread specific. To manage
137 thread-local data, just create an instance of :class:`local` (or a
148 A class that represents thread-local data.
156 Thread Objects
159 The :class:`Thread` class represents an activity that is run in a separate
160 thread of control. There are two ways to specify the activity: by passing a
161 callable object to the constructor, or by overriding the :meth:`~Thread.run`
164 :meth:`~Thread.__init__` and :meth:`~Thread.run` methods of this class.
166 Once a thread object is created, its activity must be started by calling the
167 thread's :meth:`~Thread.start` method. This invokes the :meth:`~Thread.run`
168 method in a separate thread of control.
170 Once the thread's activity is started, the thread is considered 'alive'. It
171 stops being alive when its :meth:`~Thread.run` method terminates -- either
172 normally, or by raising an unhandled exception. The :meth:`~Thread.is_alive`
173 method tests whether the thread is alive.
175 Other threads can call a thread's :meth:`~Thread.join` method. This blocks
176 the calling thread until the thread whose :meth:`~Thread.join` method is
179 A thread has a name. The name can be passed to the constructor, and read or
180 changed through the :attr:`~Thread.name` attribute.
182 A thread can be flagged as a "daemon thread". The significance of this flag is
184 initial value is inherited from the creating thread. The flag can be set
185 through the :attr:`~Thread.daemon` property or the *daemon* constructor
194 There is a "main thread" object; this corresponds to the initial thread of
195 control in the Python program. It is not a daemon thread.
197 There is the possibility that "dummy thread objects" are created. These are
198 thread objects corresponding to "alien threads", which are threads of control
200 thread objects have limited functionality; they are always considered alive and
201 daemonic, and cannot be :meth:`~Thread.join`\ ed. They are never deleted,
205 .. class:: Thread(group=None, target=None, name=None, args=(), kwargs={}, *, \
217 *name* is the thread name. By default, a unique name is constructed of the
218 form "Thread-*N*" where *N* is a small decimal number.
225 If not ``None``, *daemon* explicitly sets whether the thread is daemonic.
227 current thread.
230 base class constructor (``Thread.__init__()``) before doing anything else to
231 the thread.
238 Start the thread's activity.
240 It must be called at most once per thread object. It arranges for the
241 object's :meth:`~Thread.run` method to be invoked in a separate thread
245 on the same thread object.
249 Method representing the thread's activity.
258 Wait until the thread terminates. This blocks the calling thread until
259 the thread whose :meth:`~Thread.join` method is called terminates -- either
265 (or fractions thereof). As :meth:`~Thread.join` always returns ``None``,
266 you must call :meth:`~Thread.is_alive` after :meth:`~Thread.join` to
267 decide whether a timeout happened -- if the thread is still alive, the
268 :meth:`~Thread.join` call timed out.
271 block until the thread terminates.
273 A thread can be :meth:`~Thread.join`\ ed many times.
275 :meth:`~Thread.join` raises a :exc:`RuntimeError` if an attempt is made
276 to join the current thread as that would cause a deadlock. It is also
277 an error to :meth:`~Thread.join` a thread before it has been started
289 Old getter/setter API for :attr:`~Thread.name`; use it directly as a
294 The 'thread identifier' of this thread or ``None`` if the thread has not
296 function. Thread identifiers may be recycled when a thread exits and
297 another thread is created. The identifier is available even after the
298 thread has exited.
302 Return whether the thread is alive.
304 This method returns ``True`` just before the :meth:`~Thread.run` method
305 starts until just after the :meth:`~Thread.run` method terminates. The
310 A boolean value indicating whether this thread is a daemon thread (True)
311 or not (False). This must be set before :meth:`~Thread.start` is called,
313 from the creating thread; the main thread is not a daemon thread and
314 therefore all threads created in the main thread default to
315 :attr:`~Thread.daemon` = ``False``.
322 Old getter/setter API for :attr:`~Thread.daemon`; use it directly as a
328 In CPython, due to the :term:`Global Interpreter Lock`, only one thread
344 particular thread when locked. In Python, it is currently the lowest level
353 thread changes it to unlocked, then the :meth:`~Lock.acquire` call resets it
361 When more than one thread is blocked in :meth:`~Lock.acquire` waiting for the
362 state to turn to unlocked, only one thread proceeds when a :meth:`~Lock.release`
371 The class implementing primitive lock objects. Once a thread has acquired a
373 thread may release it.
410 Release a lock. This can be called from any thread, not only the thread
428 times by the same thread. Internally, it uses the concepts of "owning thread"
430 locks. In the locked state, some thread owns the lock; in the unlocked state,
431 no thread owns it.
433 To lock the lock, a thread calls its :meth:`~RLock.acquire` method; this
434 returns once the thread owns the lock. To unlock the lock, a thread calls
438 allows another thread blocked in :meth:`~Lock.acquire` to proceed.
446 released by the thread that acquired it. Once a thread has acquired a
447 reentrant lock, the same thread may acquire it again without blocking; the
448 thread must release it once for each time it has acquired it.
459 When invoked without arguments: if this thread already owns the lock, increment
461 thread owns the lock, block until the lock is unlocked. Once the lock is
462 unlocked (not owned by any thread), then grab ownership, set the recursion level
463 to one, and return. If more than one thread is blocked waiting until the lock
486 zero, reset the lock to unlocked (not owned by any thread), and if any other
489 nonzero, the lock remains locked and owned by the calling thread.
491 Only call this method when the calling thread owns the lock. A
516 another thread awakens it by calling :meth:`~Condition.notify` or
525 don't release the lock; this means that the thread or threads awakened will
527 the thread that called :meth:`~Condition.notify` or :meth:`~Condition.notify_all`
565 item to the buffer only needs to wake up one consumer thread.
571 allows one or more threads to wait until they are notified by another thread.
592 Wait until notified or until a timeout occurs. If the calling thread has
598 condition variable in another thread, or until the optional timeout
644 By default, wake up one thread waiting on this condition, if any. If the
645 calling thread has not acquired the lock when this method is called, a
656 Note: an awakened thread does not actually return from its :meth:`wait`
664 calling thread has not acquired the lock when this method is called, a
681 finds that it is zero, it blocks, waiting until some other thread calls
713 thread will be awoken by each call to :meth:`~Semaphore.release`. The
730 was zero on entry and another thread is waiting for it to become larger
731 than zero again, wake up that thread.
754 main thread would initialize the semaphore::
780 thread signals an event and other threads wait for it.
816 entry, return immediately. Otherwise, block until another thread calls
838 of time has passed --- a timer. :class:`Timer` is a subclass of :class:`Thread`
885 As an example, here is a simple way to synchronize a client and server thread::
918 for each thread. This can be used to select a thread to do some special
923 # Only one thread needs to print this
933 barrier is broken or reset while a thread is waiting.