Saturday, March 23, 2013

Threading

There is an excellent blog on threading in Python at http://www.tutorialspoint.com/python/python_multithreading.htm.

After reading this, I wrote some threaded code in thread_graph.py. It seems to work great!

(I chose to use the Threading module, not the Thread module, as recommended on the website, although it gives examples for using both).

Finally, in super_threading.py, I wrote some truly multi-threaded code with separate threads that are interdependent. That is the fastest code yet!

1 comment:

  1. The Python threading module uses threads instead of processes. Threads run in the same unique memory heap. Whereas Processes run in separate memory heaps. This, makes sharing information harder with processes and object instances. One problem arises because threads use the same memory heap, multiple threads can write to the same location in the memory heap which is why the global interpreter lock(GIL) in CPython was created as a mutex to prevent it from happening.

    More on....Python Threading

    ReplyDelete