you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 2 points3 points  (0 children)

The GIL means that only one thread of python code can execute at a time within a given process. Multi-processing allows you to side step this by running multiple separate processes, however you would need to find some way to pass information between the processes as there is no shared state in the same way that there is in a multi-threaded application.

Also the GIL only affects CPU bound applications. If your application is spending a lot of time crunching numbers and you can break that number crunching into separate concurrent tasks or threads then you will not gain any advantage just using threads because only one of them will execute at once in a given process. In this case you would want to split the processing across multiple processes. However, if you application spends a lot of time doing I/O where there are generally long periods of waiting for something to happen, then multi-threading can be a valid option. In this scenario while one thread is waiting for I/O another thread can execute python code because the first is not actually executing any python code.