Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add aquire_read_lock et. al. methods to ReaderWriterLock #108

Merged
merged 1 commit into from
Sep 18, 2023

Conversation

psarka
Copy link
Collaborator

@psarka psarka commented Sep 1, 2023

No description provided.

@ArneBachmannDLR
Copy link

This PR works for me. I don't know the source code too well to make an assessment, but copying the lock.py and using this adapter, I saw no errors:

class LockAdapter:
  def __init__(_, lock:ReaderWriterLock, write:bool = True) -> None: _.lock = lock; _.write = write
  def acquire(_, block:bool = True, timeout:Union[float,int] = -1) -> bool: return (_.lock.acquire_write_lock if _.write else _.lock.acquire_read_lock)()
  def release(_) -> None:                                                          (_.lock.release_write_lock if _.write else _.lock.release_read_lock)()
  def __enter__(_:Self) -> 'LockAdapter':                                   _.acquire(); return _.lock
  def __exit__(_, exc_type, exc_val, exc_tb) -> bool:                       _.release(); return True

The interface of the readerwriterlock is a bit indirect - I need to create a RWLockFairD then create a gen_rlock and then use it as context manager or acquire/release. For inter-process locks, I will test it. For threads I will stick to fasteners, once you cut a new release.

Thanks and Cheers!

@psarka psarka merged commit 2535dce into main Sep 18, 2023
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants