pals icon indicating copy to clipboard operation
pals copied to clipboard

Allow acquire timeout to be specified like for threading.Lock

Open jobh opened this issue 5 years ago • 0 comments

threading.Lock.aquire takes an argument named timeout, using seconds rather than milliseconds with -1 to indicate no timeout.

It would be nice to have a drop-in-compatible interface for pals.Lock.aquire, using something like

def aquire(self, ..., timeout=None):
    if aquire_timeout is None and timeout is not None:
        acquire_timeout = 0 if timeout<0 else 1+int(timeout*1000)

Also, in the same function: It looks like it is not currently possible to override the default aquire_timeout with 0 (no timeout) due to the acquire_timeout or ... construction. It should perhaps be changed to

    acquire_timeout = acquire_timeout if acquire_timeout is not None else self.aquire_timeout

jobh avatar Aug 20 '20 11:08 jobh