Skip to content

Commit

Permalink
Fixes timeout/block semantics
Browse files Browse the repository at this point in the history
  • Loading branch information
jsbueno committed Sep 30, 2024
1 parent b5d0e9e commit 7c98d9f
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/extrainterpreters/lock.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from threading import TIMEOUT_MAX
import time
import sys

Expand Down Expand Up @@ -105,10 +106,18 @@ def __init__(self):
self._lock = _CrossInterpreterStructLock(lock_str)

def acquire(self, blocking=True, timeout=-1):
timeout = None if timeout == -1 or not blocking else timeout
self._lock.timeout(timeout)
self._lock.__enter__()
return
if blocking:
timeout = TIMEOUT_MAX if timeout == -1 or not blocking else timeout
self._lock.timeout(timeout)
self._lock.__enter__()
return
else:
self._lock.timeout(None)
try:
self._lock.__enter__()
except ResourceBusyError:
return False
return True

def release(self):
self._lock.__exit__()
Expand Down Expand Up @@ -143,4 +152,8 @@ class RLock(IntRLock):


class Lock(IntRLock):
pass
...
#def acquire(self, blocking=True, timeout=-1):
#if self.locked():
#if not blocking or timeout == -1:

0 comments on commit 7c98d9f

Please sign in to comment.