Thread

from panda3d.core import Thread
class Thread

Bases: TypedReferenceCount, Namable

Due to a GCC bug, we can’t use alignas() together with an attribute.

Inheritance diagram

Inheritance diagram of Thread

__init__(*args, **kwargs)
bindThread()

C++ Interface: bind_thread(str name, str sync_name)

/**
  • Returns a new Panda Thread object associated with the current thread (which

  • has been created externally). This can be used to bind a unique Panda

  • Thread object with an external thread, such as a new Python thread.

  • It is particularly useful to bind a Panda Thread object to an external

  • thread for the purposes of PStats monitoring. Without this call, each

  • external thread will be assigned the same global ExternalThread object,

  • which means they will all appear in the same PStats graph.

  • It is the caller’s responsibility to save the returned Thread pointer for

  • the lifetime of the external thread. It is an error for the Thread pointer

  • to destruct while the external thread is still in the system.

  • It is also an error to call this method from the main thread, or twice

  • within a given thread, unless it is given the same name each time (in which

  • case the same pointer will be returned each time).

*/

bind_thread()

C++ Interface: bind_thread(str name, str sync_name)

/**
  • Returns a new Panda Thread object associated with the current thread (which

  • has been created externally). This can be used to bind a unique Panda

  • Thread object with an external thread, such as a new Python thread.

  • It is particularly useful to bind a Panda Thread object to an external

  • thread for the purposes of PStats monitoring. Without this call, each

  • external thread will be assigned the same global ExternalThread object,

  • which means they will all appear in the same PStats graph.

  • It is the caller’s responsibility to save the returned Thread pointer for

  • the lifetime of the external thread. It is an error for the Thread pointer

  • to destruct while the external thread is still in the system.

  • It is also an error to call this method from the main thread, or twice

  • within a given thread, unless it is given the same name each time (in which

  • case the same pointer will be returned each time).

*/

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.

*/

consider_yield()

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.

*/

current_pipeline_stage = 0
current_task
current_thread = MainThread Main
external_thread = ExternalThread External
forceYield()

C++ Interface: force_yield()

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

*/

force_yield()

C++ Interface: force_yield()

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

*/

getClassType()

C++ Interface: get_class_type()

getCurrentPipelineStage()

C++ Interface: get_current_pipeline_stage()

/**
  • Returns the integer pipeline stage associated with the current thread.

  • This is the same thing as get_current_thread()->get_pipeline_stage(), but

  • it may be faster to retrieve in some contexts.

*/

getCurrentTask()

C++ Interface: get_current_task(Thread self)

/**
  • Returns the task currently executing on this thread (via the

  • AsyncTaskManager), if any, or NULL if the thread is not currently servicing

  • a task.

*/

getCurrentThread()

C++ Interface: get_current_thread()

/**
  • Returns a pointer to the currently-executing Thread object. If this is

  • called from the main thread, this will return the same value as

  • get_main_thread().

  • This will always return some valid Thread pointer. It will never return

  • NULL, even if the current thread was spawned outside of Panda’s threading

  • system, although all non-Panda threads will return the exact same Thread

  • pointer.

*/

getExternalThread()

C++ Interface: get_external_thread()

/**
  • Returns a pointer to the “external” Thread object–this is a special Thread

  • object that corresponds to any thread spawned outside of Panda’s threading

  • interface. Note that multiple different threads may share this same

  • pointer.

*/

getMainThread()

C++ Interface: get_main_thread()

/**
  • Returns a pointer to the “main” Thread object–this is the Thread that

  • started the whole process.

*/

getPipelineStage()

C++ Interface: get_pipeline_stage(Thread self)

/**
  • Returns the Pipeline stage number associated with this thread. The default

  • stage is 0 if no stage is specified otherwise. See set_pipeline_stage().

*/

getPstatsIndex()

C++ Interface: get_pstats_index(Thread self)

/**
  • Returns the PStats index associated with this thread, or -1 if no index has

  • yet been associated with this thread. This is used internally by the

  • PStatClient; you should not need to call this directly.

*/

getPythonIndex()

C++ Interface: get_python_index(Thread self)

/**
  • Returns the Python index associated with this thread, or -1 if no index has

  • yet been associated with this thread. This is used internally by the

  • direct.stdpy.thread module; you should not need to call this directly.

*/

getSyncName()

C++ Interface: get_sync_name(Thread self)

/**
  • Returns the sync name of the thread. This name collects threads into “sync

  • groups”, which are expected to run synchronously. This is mainly used for

  • the benefit of PStats; threads with the same sync name can be ticked all at

  • once via the thread_tick() call.

*/

getUniqueId()

C++ Interface: get_unique_id(Thread self)

/**
  • Returns a string that is guaranteed to be unique to this thread, across all

  • processes on the machine, during at least the lifetime of this process.

*/

get_class_type()

C++ Interface: get_class_type()

get_current_pipeline_stage()

C++ Interface: get_current_pipeline_stage()

/**
  • Returns the integer pipeline stage associated with the current thread.

  • This is the same thing as get_current_thread()->get_pipeline_stage(), but

  • it may be faster to retrieve in some contexts.

*/

get_current_task()

C++ Interface: get_current_task(Thread self)

/**
  • Returns the task currently executing on this thread (via the

  • AsyncTaskManager), if any, or NULL if the thread is not currently servicing

  • a task.

*/

get_current_thread()

C++ Interface: get_current_thread()

/**
  • Returns a pointer to the currently-executing Thread object. If this is

  • called from the main thread, this will return the same value as

  • get_main_thread().

  • This will always return some valid Thread pointer. It will never return

  • NULL, even if the current thread was spawned outside of Panda’s threading

  • system, although all non-Panda threads will return the exact same Thread

  • pointer.

*/

get_external_thread()

C++ Interface: get_external_thread()

/**
  • Returns a pointer to the “external” Thread object–this is a special Thread

  • object that corresponds to any thread spawned outside of Panda’s threading

  • interface. Note that multiple different threads may share this same

  • pointer.

*/

get_main_thread()

C++ Interface: get_main_thread()

/**
  • Returns a pointer to the “main” Thread object–this is the Thread that

  • started the whole process.

*/

get_pipeline_stage()

C++ Interface: get_pipeline_stage(Thread self)

/**
  • Returns the Pipeline stage number associated with this thread. The default

  • stage is 0 if no stage is specified otherwise. See set_pipeline_stage().

*/

get_pstats_index()

C++ Interface: get_pstats_index(Thread self)

/**
  • Returns the PStats index associated with this thread, or -1 if no index has

  • yet been associated with this thread. This is used internally by the

  • PStatClient; you should not need to call this directly.

*/

get_python_index()

C++ Interface: get_python_index(Thread self)

/**
  • Returns the Python index associated with this thread, or -1 if no index has

  • yet been associated with this thread. This is used internally by the

  • direct.stdpy.thread module; you should not need to call this directly.

*/

get_sync_name()

C++ Interface: get_sync_name(Thread self)

/**
  • Returns the sync name of the thread. This name collects threads into “sync

  • groups”, which are expected to run synchronously. This is mainly used for

  • the benefit of PStats; threads with the same sync name can be ticked all at

  • once via the thread_tick() call.

*/

get_unique_id()

C++ Interface: get_unique_id(Thread self)

/**
  • Returns a string that is guaranteed to be unique to this thread, across all

  • processes on the machine, during at least the lifetime of this process.

*/

isJoinable()

C++ Interface: is_joinable(Thread self)

/**
  • Returns the value of joinable that was passed to the start() call.

*/

isSimpleThreads()

C++ Interface: is_simple_threads()

/**
  • Returns true if Panda is currently compiled for “simple threads”, which is

  • to say, cooperative context switching only, reducing the need for quite so

  • many critical section protections. This is not necessarily the opposite of

  • “true threads”, since one possible implementation of simple threads is via

  • true threads with mutex protection to ensure only one runs at a time.

*/

isStarted()

C++ Interface: is_started(Thread self)

/**
  • Returns true if the thread has been started, false if it has not, or if

  • join() has already been called.

*/

isThreadingSupported()

C++ Interface: is_threading_supported()

/**
  • Returns true if threading support has been compiled in and enabled, or

  • false if no threading is available (and Thread::start() will always fail).

*/

isTrueThreads()

C++ Interface: is_true_threads()

/**
  • Returns true if a real threading library is available that supports actual

  • OS-implemented threads, or false if the only threading we can provide is

  • simulated user-space threading.

*/

is_joinable()

C++ Interface: is_joinable(Thread self)

/**
  • Returns the value of joinable that was passed to the start() call.

*/

is_simple_threads()

C++ Interface: is_simple_threads()

/**
  • Returns true if Panda is currently compiled for “simple threads”, which is

  • to say, cooperative context switching only, reducing the need for quite so

  • many critical section protections. This is not necessarily the opposite of

  • “true threads”, since one possible implementation of simple threads is via

  • true threads with mutex protection to ensure only one runs at a time.

*/

is_started()

C++ Interface: is_started(Thread self)

/**
  • Returns true if the thread has been started, false if it has not, or if

  • join() has already been called.

*/

is_threading_supported()

C++ Interface: is_threading_supported()

/**
  • Returns true if threading support has been compiled in and enabled, or

  • false if no threading is available (and Thread::start() will always fail).

*/

is_true_threads()

C++ Interface: is_true_threads()

/**
  • Returns true if a real threading library is available that supports actual

  • OS-implemented threads, or false if the only threading we can provide is

  • simulated user-space threading.

*/

join()

C++ Interface: join(const Thread self)

/**
  • Blocks the calling process until the thread terminates. If the thread has

  • already terminated, this returns immediately.

*/

joinable
main_thread = MainThread Main
output()

C++ Interface: output(Thread self, ostream out)

/**

*/

outputBlocker()

C++ Interface: output_blocker(Thread self, ostream out)

/**
  • Writes a description of the mutex or condition variable that this thread is

  • blocked on. Writes nothing if there is no blocker, or if we are not in

  • DEBUG_THREADS mode.

*/

output_blocker()

C++ Interface: output_blocker(Thread self, ostream out)

/**
  • Writes a description of the mutex or condition variable that this thread is

  • blocked on. Writes nothing if there is no blocker, or if we are not in

  • DEBUG_THREADS mode.

*/

pipeline_stage
preempt()

C++ Interface: preempt(const Thread self)

/**
  • Indicates that this thread should run as soon as possible, preemptying any

  • other threads that may be scheduled to run. This may not be implemented on

  • every platform.

*/

prepareForExit()

C++ Interface: prepare_for_exit()

/**
  • Should be called by the main thread just before exiting the program, this

  • blocks until any remaining thread cleanup has finished.

*/

prepare_for_exit()

C++ Interface: prepare_for_exit()

/**
  • Should be called by the main thread just before exiting the program, this

  • blocks until any remaining thread cleanup has finished.

*/

pstats_index
python_index
relax()

C++ Interface: relax()

/**
  • Equivalent to the pause instruction on x86 or the yield instruction on ARM,

  • to be called in spin loops.

*/

setMinPipelineStage()

C++ Interface: set_min_pipeline_stage(const Thread self, int min_pipeline_stage)

/**
  • Sets this thread’s pipeline stage number to at least the indicated value,

  • unless it is already larger. See set_pipeline_stage().

*/

setPipelineStage()

C++ Interface: set_pipeline_stage(const Thread self, int pipeline_stage)

/**
  • Specifies the Pipeline stage number associated with this thread. The

  • default stage is 0 if no stage is specified otherwise.

  • This must be a value in the range [0 .. pipeline->get_num_stages() - 1].

  • It specifies the values that this thread observes for all pipelined data.

  • Typically, an application thread will leave this at 0, but a render thread

  • may set it to 1 or 2 (to operate on the previous frame’s data, or the

  • second previous frame’s data).

*/

setPythonIndex()

C++ Interface: set_python_index(const Thread self, int index)

/**
  • Stores a Python index to be associated with this thread. This is used

  • internally by the thread module; you should not need to call this directly.

*/

set_min_pipeline_stage()

C++ Interface: set_min_pipeline_stage(const Thread self, int min_pipeline_stage)

/**
  • Sets this thread’s pipeline stage number to at least the indicated value,

  • unless it is already larger. See set_pipeline_stage().

*/

set_pipeline_stage()

C++ Interface: set_pipeline_stage(const Thread self, int pipeline_stage)

/**
  • Specifies the Pipeline stage number associated with this thread. The

  • default stage is 0 if no stage is specified otherwise.

  • This must be a value in the range [0 .. pipeline->get_num_stages() - 1].

  • It specifies the values that this thread observes for all pipelined data.

  • Typically, an application thread will leave this at 0, but a render thread

  • may set it to 1 or 2 (to operate on the previous frame’s data, or the

  • second previous frame’s data).

*/

set_python_index()

C++ Interface: set_python_index(const Thread self, int index)

/**
  • Stores a Python index to be associated with this thread. This is used

  • internally by the thread module; you should not need to call this directly.

*/

simple_threads = False
sleep()

C++ Interface: sleep(double seconds)

/**
  • Suspends the current thread for at least the indicated amount of time. It

  • might be suspended for longer.

*/

start()

C++ Interface: start(const Thread self, int priority, bool joinable)

/**
  • Starts the thread executing. It is only valid to call this once.

  • The thread will begin executing its thread_main() function, and will

  • terminate when thread_main() returns.

  • priority is intended as a hint to the relative importance of this thread.

  • This may be ignored by the thread implementation.

  • joinable should be set true if you intend to call join() to wait for the

  • thread to terminate, or false if you don’t care and you will never call

  • join(). Note that the reference count on the Thread object is incremented

  • while the thread itself is running, so if you just want to fire and forget

  • a thread, you may pass joinable = false, and never store the Thread object.

  • It will automatically destruct itself when it finishes.

  • The return value is true if the thread is successfully started, false

  • otherwise.

*/

started
sync_name
threading_supported = True
true_threads = True
unique_id
upcastToNamable()

C++ Interface: upcast_to_Namable(const Thread self)

upcast from Thread to Namable

upcastToTypedReferenceCount()

C++ Interface: upcast_to_TypedReferenceCount(const Thread self)

upcast from Thread to TypedReferenceCount

upcast_to_Namable()

C++ Interface: upcast_to_Namable(const Thread self)

upcast from Thread to Namable

upcast_to_TypedReferenceCount()

C++ Interface: upcast_to_TypedReferenceCount(const Thread self)

upcast from Thread to TypedReferenceCount

writeStatus()

C++ Interface: write_status(ostream out)

/**

*/

write_status()

C++ Interface: write_status(ostream out)

/**

*/