Skip to content

Instantly share code, notes, and snippets.

@ants
Created September 1, 2016 12:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ants/c90ce6732c38fcdbf3c4a228180e5d39 to your computer and use it in GitHub Desktop.
Save ants/c90ce6732c38fcdbf3c4a228180e5d39 to your computer and use it in GitHub Desktop.
from threading import RLock, Thread
import time
running = True
def long_lock_loop(mutex):
while running:
mutex.acquire()
print "Long acquired"
time.sleep(3)
print "Long releasing"
mutex.release()
def short_lock_loop(mutex):
while running:
mutex.acquire()
print "Short acquired"
mutex.release()
time.sleep(3)
t_lock = RLock()
t1 = Thread(target=long_lock_loop, args=(t_lock,))
t2 = Thread(target=short_lock_loop, args=(t_lock,))
t1.start()
t2.start()
try:
while True:
time.sleep(60)
finally:
running = False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment