Hello
I’m encountering an issue with multi-threading in my Python application and would appreciate some guidance. I’m trying to use multi-threading to speed up a data processing task, but I’m running into a RuntimeError when starting threads. Here’s a snippet of the code that’s causing the problem:
import threading
def worker():
print("Thread is running")
threads = []
for i in range(5):
t = threading.Thread(target=worker)
threads.append(t)
t.start()
for t in threads:
t.join()
The error message I receive is:
RuntimeError: thread.init() not called
I’ve confirmed that the threading module is correctly imported and the worker function is defined properly. Despite this, the issue persists. I expected the threads to run concurrently and print messages, but instead, I get a RuntimeError indicating an issue with thread initialization. I’m using Python 3.10.2 on macOS, and I’m utilizing the standard threading library. Any help or advice on how to resolve this would be greatly appreciated. Thank you!