3 ms·
> Turns out that a Python program with ~500 threads will start to chew up memory over time. Anyone have more info about this issue? I've got a scraper myself i
by suddenclarity 3y ago
> Turns out that a Python program with ~500 threads will start to chew up memory over time.
Anyone have more info about this issue? I've got a scraper myself in Python with a few hundred threads which seems to eat a lot of memory. Any workarounds or is the only solution to rewrite in another language?
- xyzeva 3y agoPython just isn't the language for this, really. Rewriting it is the only real solution, I don't know your exact problem.
- belorn 3y agoYou can do it in python but one has to dig into how python do reference counting and how that interacts with threads. Personally I prefer using processes rather than threads, with a worker pool and a message bus rather than shared memory. That solution has its own drawbacks (and a bit more overhead), but you don't need to worry so much about memory issues. Processes also seems a better match for crawlers since the number of processes will be fairly constant and the work the processes do is fairly independent.
- dist-epoch 3y agoYou really should be using ayncio. It's a perfect fit for your usecase.
- teddyh 3y agoimport multiprocessing as threading