5.4.1. Thread — Multithreading¶
The Thread module contains functions allowing the developer to implement multithreading within a plug-in.
TODO: More information
This module defines the following functions:
- Thread.Create(function, *args, **kwargs)¶
Runs the given function in a new thread.
Parameters: - function (function) – The function to run in the new thread
- args – The arguments to pass to the function
- kwargs – The keyword arguments to pass to the function
- Thread.CreateTimer(interval, function, *args, **kwargs)¶
Runs the given function in a new thread after the given interval has elapsed.
Parameters: - interval (int) – The number of seconds to wait before running the function
- function (function) – The function to run in the new thread
- args – The arguments to pass to the function
- kwargs – The keyword arguments to pass to the function
- Thread.Lock(key)¶
Acquires a lock with the given key. Other threads trying to acquire the same lock will block until the lock is released.
Parameter: key (str) – The key of the lock to acquire Note
It is the responsibility of the developer to ensure that locks are properly released once acquired.
- Thread.Unlock(key)¶
Releases a previously acquired lock with the given key.
Parameter: key (str) – The key of the lock to release
- Thread.Sleep(secs)¶
Pauses the execution of the current thread for a given number of seconds.
Parameter: secs (int) – The number of seconds to sleep for
Note
A number of decorators are available to assist with multithreaded programming. See Multithreading decorators for more information.