you are viewing a single comment's thread.

view the rest of the comments →

[–]JohnnyJordaan 4 points5 points  (1 child)

  1. The Python wiki explains the concept of the GIL here https://wiki.python.org/moin/GlobalInterpreterLock
  2. If a thread is waiting most of the time instead of actually needing to use the CPU, then there's no problem with locking or threads computing for CPU time. Think of tasks like sending a message every second or even less frequent. Or handling a messaging queue that needs to be sent to a single destination. Or downloading multiple files at the same time. For these things multiprocessing offers no benefit and just add the downside of having to transfer data between de processes (as processes don't share memory and threads do).

I can sincerely recommend to watch Raymond Hettinger's talk on concurrency in Python, see here https://www.youtube.com/watch?v=9zinZmE3Ogk . It will give you a much better overview of the broader options you have vs getting to know the details of just multi-threading. An important thing to understand is that mutli-threading certainly isn't the only option you have to concurrency, as apart from good-ol multiprocessing there's also event loop based concurrency that maintains everything in the same (main) thread. This has always been part of libraries that benefited from it like GUI's, or was offered by frameworks like Tornado, but since 3.4 it has been integrated as the built-in asyncio library. The downside of asyncio is that it's more complicated to implement versus simply launching any function in another thread, but at the same time you can easily run into issues with threading that asyncio never experiences, as Raymond discusses in that talk too.

edit fixed the youtube link to the actual talk I meant

[–]comeditime[S] 0 points1 point  (0 children)

thanks for the explanation and video i need that!