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 Panda threading constructs. It’s designed as a drop-in replacement for the threading module for code that works with Panda; it is necessary because in some compilation models, Panda’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 Panda’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 Panda’s threads, so that Panda’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

Inheritance diagram of direct.stdpy.threading

class BoundedSemaphore(value=1)[source]

Bases: Semaphore

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

__init__(self, value=1)[source]
release(self)[source]
class Condition(lock=None)[source]

Bases: ConditionVarFull

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

__init__(self, lock=None)[source]
acquire(self, *args, **kw)[source]
notifyAll(self)[source]
release(self)[source]
wait(self, timeout=None)[source]
class Event[source]

Bases: object

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

__init__(self)[source]
clear(self)[source]
is_set(self)[source]
set(self)[source]
wait(self, timeout=None)[source]
class ExternalThread(extThread, threadId)[source]

Bases: ThreadBase

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

__init__(self, extThread, threadId)[source]
isAlive(self)[source]
is_alive(self)[source]
join(self, timeout=None)[source]
run(self)[source]
setDaemon(self, daemon)[source]
start(self)[source]
class Lock(name='PythonLock')[source]

Bases: Mutex

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

__init__(self, name='PythonLock')[source]
acquire(self, blocking=True)[source]
class MainThread(extThread, threadId)[source]

Bases: ExternalThread

Returned for the MainThread object.

__init__(self, extThread, threadId)[source]
class RLock(name='PythonRLock')[source]

Bases: ReMutex

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

__init__(self, name='PythonRLock')[source]
acquire(self, blocking=True)[source]
class Semaphore(value=1)[source]

Bases: Semaphore

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

__init__(self, value=1)[source]
acquire(self, blocking=True)[source]
class Thread(group=None, target=None, name=None, args=(), kwargs={}, daemon=None)[source]

Bases: ThreadBase

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

__init__(self, group=None, target=None, name=None, args=(), kwargs={}, daemon=None)[source]
is_alive(self)[source]
join(self, timeout=None)[source]
run(self)[source]
setName(self, name)[source]
start(self)[source]
class ThreadBase[source]

Bases: object

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

__init__(self)[source]
considerYield()

C++ Interface: consider_yield()

/**
  • Possibly suspends the current thread for the rest of the current epoch, if

  • it has run for enough this epoch. This is especially important for the

  • simple thread implementation, which relies on cooperative yields like this.

*/

forceYield()

C++ Interface: force_yield()

/**
  • Suspends the current thread for the rest of the current epoch.

*/

getName(self)[source]
isDaemon(self)[source]
setDaemon(self, daemon)[source]
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

__init__(self, interval, function, args=[], kwargs={})[source]
cancel(self)[source]

Stop the timer if it hasn’t finished yet

run(self)[source]
active_count()[source]
current_thread()[source]
enumerate()[source]
main_thread()[source]
setprofile(func)[source]
settrace(func)[source]
stack_size(size=None)[source]