question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

in InterProcessLock, __init__ should be able to set default values arguments for acquire()

See original GitHub issue

This would make its use as a context manager more flexible, eg with InterProcessLock(afile, delay=0.1, max_delay=1) as locked:

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:9

github_iconTop GitHub Comments

1reaction
pombredannecommented, Jan 7, 2021

And I have tested this at scale on ~ 20K runs and it looks fine so far! Thanks

1reaction
psarkacommented, Jan 6, 2021

This feature is definitely on the list, but I currently I don’t like the API options for it 😦

I’ll note that while I’m stuck, the exception raising one is very easy to make yourselves on top of lock by just adding the method. Like this:

from contextlib import contextmanager

from fasteners import InterProcessLock


class FailedToAcquireException(Exception):
    pass


class WithTimeout(InterProcessLock):

    @contextmanager
    def locked(self, timeout):
        ok = self.acquire(timeout=timeout)
        if not ok:
            raise FailedToAcquireException()
        try:
            yield
        finally:
            self.release()


try:
    with WithTimeout('zzz').locked(100):
        ...  # exclusive access
except FailedToAcquireException:
    ...  # manage failure

Read more comments on GitHub >

github_iconTop Results From Across the Web

Default parameters - JavaScript - MDN Web Docs
Default function parameters allow named parameters to be initialized with default values if no value or undefined is passed.
Read more >
super().__init__(...) and default values - Stack Overflow
When a parent and child class both define the same initialization parameter, but with default values, what's the best way to get sane...
Read more >
Default arguments - cppreference.com
For a member function of a non-template class, the default arguments are allowed on the out-of-class definition, and are combined with the default...
Read more >
Index (Curator Recipes 2.7.0 API) - javadoc.io
InterProcessLock : Acquire the mutex - blocks until it's available or the given ... DistributedAtomicNumber: Atomically sets the value to the given updated ......
Read more >
Default arguments in Python - GeeksforGeeks
Default values indicate that the function argument will take that value if no argument value is passed during the function call.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found