5.2.5. vlcp.event.lock


This document is generated from the source file.

View Source on GitHub

Created on 2015/12/14


Lock is created by limiting queue length of LockEvent, so there is only one event in the queue. Other send request is blocked by the queue.

class vlcp.event.lock.Lock(key, scheduler, context='default')

An lock object. Normal usage:

my_lock = Lock(lock_obj, container.scheduler)
await my_lock.lock(container)
with my_lock:

Or use async with:

async with my_lock:
__init__(key, scheduler, context='default')

Create a lock object. You do not need to share this object with other routines; all locks with the same key and context are mutual exclusive.

  • key – Any hashable value.
  • scheduler – The scheduler
  • context – An extra object to separate keys into different context

Start to acquire lock in another routine. Call trylock or lock later to acquire the lock. Call unlock to cancel the lock routine


Wait for lock acquire


Try to acquire lock and return True; if cannot acquire the lock at this moment, return False.


Unlock the key

class vlcp.event.lock.LockEvent(*args, **kwargs)

Extra criteria for an event with canignore = False. When this event returns True, the event is safely ignored.

class vlcp.event.lock.LockedEvent(*args, **kwargs)
class vlcp.event.lock.Semaphore(key, size, scheduler, context='default', priority=1000)

Change the default behavior of Lock for specified context and key from lock to semaphore. The default behavior of Lock allows only one routine for a specified key; when a semaphore is created, limited number of routines can retrieve the Lock at the same time.

__init__(key, size, scheduler, context='default', priority=1000)

Prepare to change locks on key and context to a semaphore.

  • key – Hashable object used by locks.
  • size – Semaphore size, which means the maximum allowed routines to retrieve the lock at the same time
  • scheduler – The scheduler
  • context – context object used by locks.
  • priority – priority for the created queue.

Create the subqueue to change the default behavior of Lock to semaphore.


Destroy the created subqueue to change the behavior back to Lock