Powered by Ajaxy
Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Python: start a thread

import thread
import time
def print_time(myThread, delay):
    while 1:
        time.sleep(delay)
        print "%s: %s" % (myThread, time.ctime(ti

Python: Using thread-local storage

import threading
local_T = threading.local( )
print 'In main Thread, shared_var set to 32'
local_T.shared_var = 32
def sub_Thread( ):
  print 'In S

Python: Lock or unlock an object using mutually exclusive access

import thread
def counter(myId, val):
    for i in range(val):
        mutex.acquire()               
        print '[%s] => %s' % (myId, i)