Thinking about Concurrency, Raymond Hettinger, Python core developer

By: Василий Айтипиплов

616   9   38262

Uploaded on 07/13/2016

Comments (6):

By anonymous    2017-09-20

Never try to kill a thread from something external to that thread. You never know if that thread is holding a lock. Python doesn’t provide a direct mechanism for kill threads externally; however, you can do it using ctypes, but that is a recipe for a deadlock.

This quote is from Raymond Hettinger, there is a speech about this.

Original Thread

By anonymous    2017-09-20

Raymond Hettinger gave a really good keynote talk about the proper way to think about concurrency and multithreading here: https://www.youtube.com/watch?v=Bv25Dwe84g0&t=2

And his notes can be found here: https://dl.dropboxusercontent.com/u/3967849/pyru/_build/html/index.html

What I recommend, which is from the talk, is to use an atomic message queue to "talk" between the threads. However, this talk and Raymond's work is done in 3.5 or 3.6. This library https://docs.python.org/3/library/queue.html will help you significantly.

Original Thread

By anonymous    2017-09-20

No, Python does have multithreading. In fact, it uses system threads. The problem is just that it can't use more than one of the available cores. This is due to something called the GIL(Global Interpreter Lock). Python threads still work for I/O bound tasks as opposed to CPU bound tasks which may cause deadlocks and race conditions. Many Python libraries solve this issue by using C extensons to bypass the GIL. Of course, this is all in the case of CPython.

There is a very interesting talk about this by one of the core developers of Python.

Thinking about concurrency, Raymond Hettinger

Now you are right, it is much better to use multiprocessing to get the benefit of all the cores. But there are much fewer cores than there are threads. Cores are valuable resources and take up a lot of memory. If you don't mind dealing with IPC(Interprocess Communication), then it is a great solution.

Original Thread

Recommended Books

    Submit Your Video

    If you have some great dev videos to share, please fill out this form.