From 7c98d9f6a035f5485bee203bf3936bd2143bce60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20S=2E=20O=2E=20Bueno?= Date: Mon, 30 Sep 2024 20:04:35 -0300 Subject: [PATCH] Fixes timeout/block semantics --- src/extrainterpreters/lock.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/extrainterpreters/lock.py b/src/extrainterpreters/lock.py index 3d384bd..c1eb074 100644 --- a/src/extrainterpreters/lock.py +++ b/src/extrainterpreters/lock.py @@ -1,3 +1,4 @@ +from threading import TIMEOUT_MAX import time import sys @@ -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__() @@ -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: +