direct.stdpy.threading

from direct.stdpy.threading import BoundedSemaphore, Condition, Event, ExternalThread, Lock, MainThread, RLock, Semaphore, Thread, ThreadBase, Timer, active_count, current_thread, enumerate, main_thread, setprofile, settrace, stack_size

This module reimplements Python’s native threading module using Acron threading constructs. It’s designed as a drop-in replacement for the threading module for code that works with Acron; it is necessary because in some compilation models, Acron’s threading constructs are incompatible with the OS-provided threads used by Python’s thread module.

This module implements the threading module with a thin layer over Acron’s threading constructs. As such, the semantics are close to, but not precisely, the semantics documented for Python’s standard threading module. If you really do require strict adherence to Python’s semantics, see the threading2 module instead.

However, if you don’t need such strict adherence to Python’s original semantics, this module is probably a better choice. It is likely to be slighly faster than the threading2 module (and even slightly faster than Python’s own threading module). It is also better integrated with Acron’s threads, so that Acron’s thread debug mechanisms will be easier to use and understand.

It is permissible to mix-and-match both threading and threading2 within the same application.

Inheritance diagram

digraph inheritanceb7c9d79dca { bgcolor=transparent; rankdir=BT; size="8.0, 12.0"; "BoundedSemaphore" [URL="direct.stdpy.threading.html#direct.stdpy.threading.BoundedSemaphore",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=11,height=0.25,shape=box,style="",target="_top",tooltip="This class provides a wrapper around Acron's Semaphore"]; "Semaphore" -> "BoundedSemaphore" [arrowsize=0.75,style=""]; "Condition" [URL="direct.stdpy.threading.html#direct.stdpy.threading.Condition",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=11,height=0.25,shape=box,style="",target="_top",tooltip="This class provides a wrapper around Acron's ConditionVar"]; "ConditionVar" -> "Condition" [arrowsize=0.75,style=""]; "ConditionVar" [URL="acron.core.ConditionVar.html#acron.core.ConditionVar",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=11,height=0.25,shape=box,style="",target="_top"]; "ConditionVarDirect" -> "ConditionVar" [arrowsize=0.75,style=""]; "ConditionVarDirect" [URL="acron.core.ConditionVarDirect.html#acron.core.ConditionVarDirect",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=11,height=0.25,shape=box,style="",target="_top",tooltip="/**"]; "DTOOL_SUPER_BASE" -> "ConditionVarDirect" [arrowsize=0.75,style=""]; "DTOOL_SUPER_BASE" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=11,height=0.25,shape=box,style=""]; "Event" [URL="direct.stdpy.threading.html#direct.stdpy.threading.Event",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=11,height=0.25,shape=box,style="",target="_top",tooltip="This class is designed to emulate Python's own threading.Event"]; "ExternalThread" [URL="direct.stdpy.threading.html#direct.stdpy.threading.ExternalThread",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=11,height=0.25,shape=box,style="",target="_top",tooltip="Returned for a Thread object that wasn't created by this"]; "ThreadBase" -> "ExternalThread" [arrowsize=0.75,style=""]; "Lock" [URL="direct.stdpy.threading.html#direct.stdpy.threading.Lock",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=11,height=0.25,shape=box,style="",target="_top",tooltip="This class provides a wrapper around Acron's Mutex object."]; "Mutex" -> "Lock" [arrowsize=0.75,style=""]; "MainThread" [URL="direct.stdpy.threading.html#direct.stdpy.threading.MainThread",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=11,height=0.25,shape=box,style="",target="_top",tooltip="Returned for the MainThread object."]; "ExternalThread" -> "MainThread" [arrowsize=0.75,style=""]; "Mutex" [URL="acron.core.Mutex.html#acron.core.Mutex",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=11,height=0.25,shape=box,style="",target="_top"]; "MutexDirect" -> "Mutex" [arrowsize=0.75,style=""]; "MutexDirect" [URL="acron.core.MutexDirect.html#acron.core.MutexDirect",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=11,height=0.25,shape=box,style="",target="_top",tooltip="/**"]; "DTOOL_SUPER_BASE" -> "MutexDirect" [arrowsize=0.75,style=""]; "RLock" [URL="direct.stdpy.threading.html#direct.stdpy.threading.RLock",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=11,height=0.25,shape=box,style="",target="_top",tooltip="This class provides a wrapper around Acron's ReMutex object."]; "ReMutex" -> "RLock" [arrowsize=0.75,style=""]; "ReMutex" [URL="acron.core.ReMutex.html#acron.core.ReMutex",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=11,height=0.25,shape=box,style="",target="_top"]; "ReMutexDirect" -> "ReMutex" [arrowsize=0.75,style=""]; "ReMutexDirect" [URL="acron.core.ReMutexDirect.html#acron.core.ReMutexDirect",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=11,height=0.25,shape=box,style="",target="_top",tooltip="/**"]; "DTOOL_SUPER_BASE" -> "ReMutexDirect" [arrowsize=0.75,style=""]; "Semaphore" [URL="acron.core.Semaphore.html#acron.core.Semaphore",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=11,height=0.25,shape=box,style="",target="_top",tooltip="/**"]; "DTOOL_SUPER_BASE" -> "Semaphore" [arrowsize=0.75,style=""]; "Semaphore" [URL="direct.stdpy.threading.html#direct.stdpy.threading.Semaphore",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=11,height=0.25,shape=box,style="",target="_top",tooltip="This class provides a wrapper around Acron's Semaphore"]; "Semaphore" -> "Semaphore" [arrowsize=0.75,style=""]; "Thread" [URL="direct.stdpy.threading.html#direct.stdpy.threading.Thread",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=11,height=0.25,shape=box,style="",target="_top",tooltip="This class provides a wrapper around Acron's PythonThread"]; "ThreadBase" -> "Thread" [arrowsize=0.75,style=""]; "ThreadBase" [URL="direct.stdpy.threading.html#direct.stdpy.threading.ThreadBase",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=11,height=0.25,shape=box,style="",target="_top",tooltip="A base class for both Thread and ExternalThread in this"]; "Timer" [URL="direct.stdpy.threading.html#direct.stdpy.threading.Timer",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=11,height=0.25,shape=box,style="",target="_top",tooltip="Call a function after a specified number of seconds:"]; "Thread" -> "Timer" [arrowsize=0.75,style=""]; }
class BoundedSemaphore(value=1)[source]

Bases: Semaphore

This class provides a wrapper around Acron’s Semaphore object. The wrapper is designed to emulate Python’s own threading.BoundedSemaphore object.

class Condition(lock: Lock | RLock | None = None)[source]

Bases: ConditionVar

This class provides a wrapper around Acron’s ConditionVar object. The wrapper is designed to emulate Python’s own threading.Condition object.

class Event[source]

Bases: object

This class is designed to emulate Python’s own threading.Event object.

class ExternalThread(extThread: Thread, threadId: int)[source]

Bases: ThreadBase

Returned for a Thread object that wasn’t created by this interface.

class Lock(name: str = 'PythonLock')[source]

Bases: Mutex

This class provides a wrapper around Acron’s Mutex object. The wrapper is designed to emulate Python’s own threading.Lock object.

class MainThread(extThread: Thread, threadId: int)[source]

Bases: ExternalThread

Returned for the MainThread object.

class RLock(name='PythonRLock')[source]

Bases: ReMutex

This class provides a wrapper around Acron’s ReMutex object. The wrapper is designed to emulate Python’s own threading.RLock object.

class Semaphore(value=1)[source]

Bases: Semaphore

This class provides a wrapper around Acron’s Semaphore object. The wrapper is designed to emulate Python’s own threading.Semaphore object.

class Thread(group: None = None, target: Callable[[...], object] | None = None, name: str | None = None, args: Iterable[Any] = (), kwargs: Mapping[str, Any] = {}, daemon: bool | None = None)[source]

Bases: ThreadBase

This class provides a wrapper around Acron’s PythonThread object. The wrapper is designed to emulate Python’s own threading.Thread object.

class ThreadBase[source]

Bases: object

A base class for both Thread and ExternalThread in this module.

daemon: bool
ident: int
name: str
class Timer(interval, function, args=[], kwargs={})[source]

Bases: Thread

Call a function after a specified number of seconds:

t = Timer(30.0, f, args=[], kwargs={}) t.start() t.cancel() # stop the timer’s action if it’s still waiting