GithubHelp home page GithubHelp logo

Comments (9)

wolph avatar wolph commented on June 24, 2024

You are largely correct but you've glossed over a small detail, the directory is randomized by the tempfile.gettempdir() function:

def __init__(
self,
maximum: int,
name: str = 'bounded_semaphore',
filename_pattern: str = '{name}.{number:02d}.lock',
directory: str = tempfile.gettempdir(),
timeout: typing.Optional[float] = DEFAULT_TIMEOUT,
check_interval: typing.Optional[float] = DEFAULT_CHECK_INTERVAL,
fail_when_locked: typing.Optional[bool] = True,
):
self.maximum = maximum
self.name = name
self.filename_pattern = filename_pattern
self.directory = directory
self.lock: typing.Optional[Lock] = None
super().__init__(
timeout=timeout,
check_interval=check_interval,
fail_when_locked=fail_when_locked,
)

In practice you will never have 2 unrelated applications colliding :)

from portalocker.

dhoulder avatar dhoulder commented on June 24, 2024

tempfile.gettempdir() always returns /tmp for me (Ubuntu, not setting TMPDIR, TEMP or TMP). See https://docs.python.org/3/library/tempfile.html#tempfile.gettempdir

>>> import tempfile
>>> tempfile.gettempdir()
'/tmp'

from portalocker.

wolph avatar wolph commented on June 24, 2024

Oops... in that case I have made a wrong assumption a long time ago and created a semaphore that could cause issues in some cases.

I'm in the process of creating a new release anyhow so I'll make sure to add your suggested NamedBoundedSemaphore class

from portalocker.

dhoulder avatar dhoulder commented on June 24, 2024

No worries. Happens to the best of us 😄
Thanks for all your hard work.

from portalocker.

wolph avatar wolph commented on June 24, 2024

As a backstory, I'm guessing this made me think it was random. On my laptop I get this:

>>> tempfile.gettempdir()
'/var/folders/y7/n86bj8vn48vftzwyzdwdpvtc0000gn/T'

Seemed pretty random to me ;)

from portalocker.

dhoulder avatar dhoulder commented on June 24, 2024

Hmm… Is that inside some kind of container or WSL on Windows or something?

from portalocker.

wolph avatar wolph commented on June 24, 2024

No... that's on OS X

from portalocker.

dhoulder avatar dhoulder commented on June 24, 2024

OK, so that seems to be a per-user $TMPDIR. I think my original observation mostly still holds: Two unrelated applications running as the same user on the same host could interfere with each other.

from portalocker.

wolph avatar wolph commented on June 24, 2024

Your observation is correct indeed. If I start 2 completely unrelated applications I get the same results.

Furthermore:

$ echo $TMPDIR
/var/folders/y7/n86bj8vn48vftzwyzdwdpvtc0000gn/T/

I really should have read the Python manual, it's pretty clear about this :X

from portalocker.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.