Question

I've been using threading class alot in my Python codes and have successfully make a couple routine to run as multi-threaded. The problem is when something fails, it becomes a pain when it comes to debugging. This is what my code block would look like:

threads = []
for argument in get_file_method():
    thread = threading.Thread(self._routine, argument)
    thread.start()
    threads.append(thread)

# Wait for all threads to complete
for thread in threads:
    filename = thread.join()

The question is, How can I force the program to run as single threaded in order to ease debug.

Was it helpful?

Solution

There is a dummy_threading module in standard library that you can use instead of threading. It offers the same inteface but runs code sequentially (start returns when the thread has finished). Of course, your threads must not rely on each other to work in parallel.

import dummy_threading as threading
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top