schrodinger.utils.thread_utils module

Simplifies keeping track of threads, mainly for debugging. Allows threads to be named and provides a print function that prepends which info on what thread it is being called from. To use, either instantiate the class or use the global singleton via the module-level functions.

class schrodinger.utils.thread_utils.ThreadTool

Bases: object

__init__()
getThreadId(name=None)

Gets an integer id for a thread. If no name is provided, gets the id of the thread that is calling this method.

Parameters

name (str) – a previously set name for a thread

Returns

a thread id

Return type

int

getThreadName(tid=None)

Gets the name of a thread if it has been previously set, otherwise just return a string representation of the thread id.

If no thread id is specified, use the id of the thread that is calling this method.

Parameters

tid (int or None) – the id of the thread for which to retrieve the name

Returns

the assigned name for the thread

Return type

str

setThreadName(name, tid=None)

Set a user-friendly name for a thread.

If no thread id is specified, use the id of the thread that is calling this method.

Parameters
  • name (str) – the name to assign (e.g. “main”, “worker”, “gui” etc.)

  • tid (int or None) – the id of the thread for which to set a name

threadPrint(*args)

Use in place of a normal print to prepend information about which thread is calling this print function.

schrodinger.utils.thread_utils.get_thread_id(name=None)
schrodinger.utils.thread_utils.get_thread_name(tid=None)
schrodinger.utils.thread_utils.set_thread_name(name, tid=None)
schrodinger.utils.thread_utils.thread_print(*args)
schrodinger.utils.thread_utils.in_main_thread()

Returns True when called from the main application thread. Otherwise returns False.