문제

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.

도움이 되었습니까?

해결책

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top