Python

Python Thread IDs

Python threading module and thread IDs In multithreaded Python applications, keeping up with what is happening in each thread can be nonintuitive. Context As a motivating example, consider the benchmark harness Rally. Rally makes heavy use of parallelism, through both the multiprocessing and threading Python modules, to provide concurrency for benchmarking. Consider a simple Rally scenario where the user wants to create a network, subnet, and boot a VM attached to that subnet.

Python "Thread-locality"

Python threading module and thread-local objects The __init__() body of Python threading.Threads runs in the main thread. Any Thread-local setup must be done inside of the threading.Thread.run() body; for example, SQLAlchemy`s thread-local scoped_session must be invoked inside of each thread to avoid conflicts/race conditions/etc. Here is a simple example: ### threading-example.py (python 2.6+) from threading import Thread, current_thread class BadThread(Thread): def __init__(self): Thread.__init__(self) self.current_thread = current_thread() def run(self): pass class GoodThread(Thread): def __init__(self): Thread.