streamlitextras.threader package
- last_trigger_time(unique_id: str = 'default') int[source]
Returns the seconds since last writing the trigger file
- trigger_rerun(unique_id: str = 'default', last_write_margin: int = 1, delay: int = 0) None[source]
Triggers treamlit to rerun the current page state. runOnSave must be set to true in config.toml
- Parameters
unique_id (str) – Unique ID to be triggered, should be set per session e.g. user id or a hash you create in their session state.
last_write_margin (int) – If the file was modified less than this many seconds ago, the rerun will not be performed
delay (int) – sleep for this many seconds before writing the rerun trigger
- thread_wrapper(thread_func, rerun_st=True, last_write_margin: int = 1, delay: int = 0, trigger_unique_id: str = 'default', *args, **kwargs) None[source]
Wrapper for running thread functions For parameters see streamlit_thread() and trigger_rerun()
- streamlit_thread(thread_func: Callable, args: tuple = (), kwargs: dict = {}, rerun_st: bool = True, last_write_margin: int = 1, delay: int = 0, script_run_context: Optional[ScriptRunContext] = None, autostart: bool = True, trigger_unique_id: str = 'default', error_handler: Optional[Callable] = None) str[source]
Spawns and starts a threading.Thread that runs thread_func with the passed args and kwargs
- Parameters
thread_func (Callable) – The function to run in the thread
args (tuple) – The args to pass to the function in the thread
kwargs (dict) – The kwargs to pass to the function in the thread
rerun_st (bool) – Whether to rerun streamlit after the thread function finishes
error_handler (Callable) – Error handler function that takes the thread exception as an argument
- Returns
The name of the thread. Can use get_thread to get the threading.Thread instance
- get_thread(thread_name) Optional[Thread][source]
Gets the threading.Thread instance thats name attribute matches thread_name
- Parameters
thread_name – The name attribute of the thread to look for.
- Returns
The threading.Thread or None if theres no thread with the supplied thread_name
- class PropagatingThread(*args, **kwargs)[source]
Bases:
Thread- run()[source]
Method representing the thread’s activity.
You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.
- join(timeout=None)[source]
Wait until the thread terminates.
This blocks the calling thread until the thread whose join() method is called terminates – either normally or through an unhandled exception or until the optional timeout occurs.
When the timeout argument is present and not None, it should be a floating point number specifying a timeout for the operation in seconds (or fractions thereof). As join() always returns None, you must call is_alive() after join() to decide whether a timeout happened – if the thread is still alive, the join() call timed out.
When the timeout argument is not present or None, the operation will block until the thread terminates.
A thread can be join()ed many times.
join() raises a RuntimeError if an attempt is made to join the current thread as that would cause a deadlock. It is also an error to join() a thread before it has been started and attempts to do so raises the same exception.