Skip to content

Instantly share code, notes, and snippets.

@Disassembler0
Created October 30, 2018 07:20
Show Gist options
  • Select an option

  • Save Disassembler0/3297f4f4e86a95507265d45192f3e0bc to your computer and use it in GitHub Desktop.

Select an option

Save Disassembler0/3297f4f4e86a95507265d45192f3e0bc to your computer and use it in GitHub Desktop.
from threading import Lock
@contextmanager
def nonblocking(lock=Lock()):
locked = lock.acquire(False)
try:
yield locked
finally:
if locked:
lock.release()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment