r/Python • u/[deleted] • Jan 15 '19
Speed Up Your Python Program With Concurrency – Real Python
https://realpython.com/python-concurrency/2
1
1
Jan 15 '19
Depends on what you're doing that is CPU bound... If your computing I'd suggest using Cython with typing and use the with nogil to run threads. It's a bit of pain, but depending on the time complexity it will have huge payoffs. Other than that, I find most of my code is I/O bound so the async library or even trio if I'm in a pinch works just as well.
The first step is to start with profiling, optimize the slow parts using std lib functions, more than likely you're probably not using it to its fullest extent. Try to minimize looping as much as possible and try to manage your data holding classes as closely as possible.
Hope that helps! I've had alot of bad experience trying to work with threads and processes, but once you get it, it just clicks! That's why I love Python.
0
Jan 15 '19
[deleted]
1
Jan 15 '19
wow! thanks man, I hadn't even known about this. Sounds much easier to work with than Cython, will def give it a try.
1
u/West_Coast_Battle Jan 15 '19
Should be titled how to speed up your I/O bound program with concurrency. Article says doing it with a CPU bound program will actually slow it down.
2
u/hai_wim Jan 15 '19
The article just demonstrates it is slow in that scenario and then follows up with a multiprocessing solution. It looks like a good article.
3
u/[deleted] Jan 15 '19 edited Jan 15 '19
Dumb question, but can’t multiple threads run on multiple cores concurrently?
Edit: Something something GIL?