Jack_90 Jack_90 - 1 year ago 97
Python Question

Multithreaded parsing is slower then sequential

I am parsing 4 large XML files through threads and somehow the multithreaded code is slower then the sequential code?

Answer Source

Python uses the GIL (Global Interpreter Lock) to ensure only one thread executes Python code at a time. This is done to prevent data races and for some other reasons. That, however, means that multithreading in the default CPython will barely give you any code speedup (if it won't slow it down, as it did in your case).
To efficiently parallelize your workload, look into Python's multiprocessing module, which instead launches separate processes that are not affected by each other's GIL

Here's a SO question on that topic

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download