I'm quite new to threading in Python and have a couple of beginner questions.
When starting more than say fifty threads using the Python threading
module I start getting MemoryError
. The threads themselves are very slim and not very memory hungry, so it seems like it is the overhead of the threading that causes the memory issues.
threading
module? Did you do any tricks to achieve that number?threading
module?Your question cannot be answered in a general way, as good usage of threading always depends on concrete problem to be solved. You also do not tell us, which Python version you are using, so I assume you use the "default" CPython and not IronPython or something like that. To give you some hints and ideas to further think about your problem:
The Global Interpreter Lock is known to have a strong impact on the performance limitations of standard CPython. Thus the multiprocessing module notes:
multiprocessing is a package that supports spawning processes using an API similar to the threading module. The multiprocessing package offers both local and remote concurrency, effectively side-stepping the Global Interpreter Lock by using subprocesses instead of threads. Due to this, the multiprocessing module allows the programmer to fully leverage multiple processors on a given machine. It runs on both Unix and Windows.
The GIL probably isn't the cause of your MemoryErrors, but it is something to be aware of.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With