Python code performance decreases with threading

后端 未结 2 797
有刺的猬
有刺的猬 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.

提交回复
热议问题