Python code performance decreases with threading

后端 未结 2 775
有刺的猬
有刺的猬 2020-11-30 05:04

I\'ve written a working program in Python that basically parses a batch of binary files, extracting data into a data structure. Each file takes around a second to parse, whi

相关标签:
2条回答
  • 2020-11-30 05:24

    This is sadly how things are in CPython, mainly due to the Global Interpreter Lock (GIL). Python code that's CPU-bound simply doesn't scale across threads (I/O-bound code, on the other hand, might scale to some extent).

    There is a highly informative presentation by David Beazley where he discusses some of the issues surrounding the GIL. The video can be found here (thanks @Ikke!)

    My recommendation would be to use the multiprocessing module instead of multiple threads.

    0 讨论(0)
  • 2020-11-30 05:34

    The threading library does not actually utilize multiple cores simultaneously for computation. You should use the multiprocessing library instead for computational threading.

    0 讨论(0)
提交回复
热议问题