def f(x): with Lock('x') as lock: client = get_client() assert client.get_metadata('locked') is False client.set_metadata('locked', True) sleep(0.05) assert client.get_metadata('locked') is True client.set_metadata('locked', False)
def f(x): with Lock("x") as lock: client = get_client() assert client.get_metadata("locked") is False client.set_metadata("locked", True) sleep(0.05) assert client.get_metadata("locked") is True client.set_metadata("locked", False)
def f(_): client = get_client() with MultiLock(names=["x"]): assert client.get_metadata("locked") is False client.set_metadata("locked", True) sleep(0.05) assert client.get_metadata("locked") is True client.set_metadata("locked", False)
def f(x): with Lock('x') as lock: client = get_client() assert client.get_metadata('locked') is False client.set_metadata('locked', True) sleep(0.05) assert client.get_metadata('locked') is True client.set_metadata('locked', False)
def guaranteed_lease_timeout(x, sem): """ This function simulates a payload computation with some GIL locking in the beginning. To simulate this we will manually disable the refresh callback, i.e. all leases will eventually timeout. The function will only release/return once the "Event" is set, i.e. our observer is done. """ sem.refresh_leases = False client = get_client() with sem: # This simulates a task which holds the GIL for longer than the # lease-timeout. This is twice the lease timeout to ensurre that the # leases are actually timed out slowidentity(delay=0.2) assert sem._leases # Now the GIL is free again, i.e. we enable the callback again sem.refresh_leases = True sleep(0.1) # This is the poormans Event.wait() while client.get_metadata("release") is not True: sleep(0.05) assert sem.get_value() >= 1 return x