#!/usr/bin/env python

import time
import thread

def myfunction(string,sleeptime,lock,*args):
    while 1:
        #print string," Looking for Lock"
        lock.acquire()
        print string," Now Sleeping after Lock acquired for ",sleeptime
        time.sleep(sleeptime) #sleep for a specified amount of time.
        print string," Now releasing lock and then sleeping again"
        lock.release()
        #time.sleep(sleeptime)

if __name__=="__main__":

    lock=thread.allocate_lock()
    thread.start_new_thread(myfunction,("Thread No:1",2,lock))
    thread.start_new_thread(myfunction,("Thread No:2",2,lock))

    while 1:
        pass



    
