py-sherlock / sherlock

Easy distributed locks for Python with a choice of backends.
MIT License
374 stars 35 forks source link

`timeout=0` doesn't work #54

Closed violuke closed 1 year ago

violuke commented 1 year ago

Firstly, thanks for the great package

I wanted to set timeout=0 to effectively have just one attempt to get the lock, but the code is as follows:

        if kwargs.get('timeout'):
            self.timeout = kwargs['timeout']
        else:
            self.timeout = _configuration.timeout

And so the 0 is Falsey and it instead uses _configuration.timeout when it shouldn't.

I'd suggest this be changed to:

        if 'timeout' in kwargs:
            self.timeout = kwargs['timeout']
        else:
            self.timeout = _configuration.timeout

Thanks.

judahrand commented 1 year ago

Hey @violuke

Do you want to submit that change in a PR? Looks like a reasonable solution!

violuke commented 1 year ago

Thanks @judahrand that's done :+1: