SharedThread
Inherits: Resource
Resource that allows nodes to run in a separate thread
Description
NodeThreads can belong to a SharedThread which will run their _thread_process method in the given thread
Properties
| Type | Name | Default |
|---|---|---|
| Thread | thread | |
| Mutex | mutex | |
| int | tid | -1 |
| bool | running | false |
| SharedThread.ExecutingTask | executing_task | |
| NodeThread[] | nodes | [] |
| Callable[] | process_funcs | [] |
| SharedThread.ScheduledTask[] | scheduled_funcs | [] |
| Callable[] | one_shots | [] |
| int | last_time | |
| int | task_id_count | 0 |
| CustomLogger | logger | |
| String | name | "SharedThread" |
| int | target_tick_rate | 60 |
| int | niceness | 0 |
| Variant | watchdog_enabled | true |
Methods
| Returns | Signature |
|---|---|
| void | start() |
| void | stop() |
| int | set_priority(value: int) |
| void | add_node(node: NodeThread) |
| void | remove_node(node: NodeThread, stop_on_empty: bool = true) |
| Variant | exec(method: Callable) |
| int | scheduled_exec(method: Callable, wait_time_ms: int, task_type: int = 0) |
| void | cancel_scheduled_exec(task_id: int) |
| void | add_process(method: Callable) |
| void | remove_process(method: Callable) |
| SharedThread.ExecutingTask | get_executing_task() |
| int | get_target_frame_time() |
Property Descriptions
thread
Thread thread
Note
There is currently no description for this property. Please help us by contributing one!
mutex
Mutex mutex
Note
There is currently no description for this property. Please help us by contributing one!
tid
int tid = -1
Note
There is currently no description for this property. Please help us by contributing one!
running
bool running = false
Note
There is currently no description for this property. Please help us by contributing one!
executing_task
SharedThread.ExecutingTask executing_task
Note
There is currently no description for this property. Please help us by contributing one!
nodes
NodeThread[] nodes = []
Note
There is currently no description for this property. Please help us by contributing one!
process_funcs
Callable[] process_funcs = []
Note
There is currently no description for this property. Please help us by contributing one!
scheduled_funcs
SharedThread.ScheduledTask[] scheduled_funcs = []
Note
There is currently no description for this property. Please help us by contributing one!
one_shots
Callable[] one_shots = []
Note
There is currently no description for this property. Please help us by contributing one!
last_time
int last_time
Note
There is currently no description for this property. Please help us by contributing one!
task_id_count
int task_id_count = 0
Note
There is currently no description for this property. Please help us by contributing one!
logger
CustomLogger logger
Note
There is currently no description for this property. Please help us by contributing one!
name
String name = "SharedThread"
Name of the thread group
target_tick_rate
int target_tick_rate = 60
Target rate to run at in ticks per second
niceness
int niceness = 0
Priority (niceness) of the thread
watchdog_enabled
Variant watchdog_enabled = true
If watchdog should be enabled on this thread
Method Descriptions
start()
void start()
Starts the thread for the thread group
stop()
void stop()
Stops the thread for the thread group
set_priority()
Set the given thread niceness to the given value. Note: in order to set negative nice value, this must be run: setcap 'cap_sys_nice=eip'
add_node()
void add_node(node: NodeThread)
Add the given NodeThread to the list of nodes to process. This should happen automatically by the NodeThread
remove_node()
void remove_node(node: NodeThread, stop_on_empty: bool = true)
Remove the given NodeThread from the list of nodes to process. This should happen automatically when the NodeThread exits the scene tree.
exec()
Variant exec(method: Callable)
Calls the given method from the thread. Internally, this queues the given method and awaits it to be called during the process loop. You should await this method if your method returns something. E.g. codevar result = await thread_group.exec(myfund.bind("myarg"))/code
scheduled_exec()
int scheduled_exec(method: Callable, wait_time_ms: int, task_type: int = 0)
Calls the given method from the thread after 'wait_time_ms' has passed. By default, this method will execute as a "oneshot" task. Optionally, the "task_type" parameter can be set to "RECURRING" if this task should run every 'wait_time_ms'.
cancel_scheduled_exec()
void cancel_scheduled_exec(task_id: int)
Cancels a given Sheduled Task
add_process()
void add_process(method: Callable)
Adds the given method to the thread process loop. This method will be called every thread tick.
remove_process()
void remove_process(method: Callable)
Removes the given method from the thread process loop.
get_executing_task()
SharedThread.ExecutingTask get_executing_task()
Returns the currently executing task
get_target_frame_time()
int get_target_frame_time()
Returns the target frame time in microseconds of the SharedThread