5. threading
• Locks
• Reentrant Locks
Reentrant knows who
own the locks and the
recursion level
• Conditions
Additional classes like
Queue.Queue
• Semaphores
• Events
• Timers
6.
7. This GIL From David Beeazley’s GIL Visualization
http://www.dabeaz.com/GIL/gilvis/fourthread.html
9. multiprocessing module
• All the things threading has • Connections
• Exchanging Objects • Managers TCP Server coordinating
shared objects
• Queues and Pipes • SyncManager Process Sync
• Shared State • Logging
• Pipes and Queues
• Pools
10. from multiprocessing import Process
import time
class MyThread(Process):
def run(self):
print "%s running" % self.name
time.sleep(5)
print "%s done" % self.name
for x in xrange(0,10):
thread = MyThread()
thread.start()
thread.join(0)
13. # Process #1
from multiprocessing.reduction import reduce_handle
import socket
# Create a socket
sock = socket.socket(socket.AF_INET,
socket.SOCK_STREAM, 0)
# Do stuff here, client or server wise
# Create the pickled socket handle
handle = reduce_handle(sock.fileno)
# Process #2
from multiprocessing.reduction import rebuild_handle
import socket
# In other process
fd = rebuild_handle(handle)
sock = socket.fromfd(fd, socket.AF_INET,
socket.SOCK_STREAM)
# Now I can read and write from the socket too