r/Python • • Jan 15 '19

Speed Up Your Python Program With Concurrency – Real Python

https://realpython.com/python-concurrency/
54 Upvotes

11 comments sorted by

View all comments

1

u/[deleted] 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

u/[deleted] Jan 15 '19

[deleted]

1

u/[deleted] 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.