You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi there, thanks for the package. A perhaps naive question, but the following behaviour seemed unintuitive to me. In short, if you chain method calls and don't assign the result to a variable, you don't acquire the lock. However, if you do assign the result, even to _, you acquire the lock. I must be missing something, but I can't tell what.
A minimum reproducible example is below.
importtempfilefrompathlibimportPathimportfilelocklock_file=Path(tempfile.mkdtemp()) /"index.json.lock"# For some reason, this doesn't cause the lock to actually be acquired.filelock.SoftFileLock(lock_file).acquire()
print(f"{lock_file.exists()=}")
# But this does_=filelock.SoftFileLock(lock_file).acquire()
print(f"{lock_file.exists()=}")
For what it's worth, I suspect the same underlying confusion causes this and #400. (#400 seems to also be a confusion about the flow, because the acquire method does take polling_interval as an argument, but it is true that __enter__ does not. Maybe the answer is, "Always use acquire as a context manager, never antying else". If that is the answer, all fine, but it might be worth clarifying and updating the docs as current examples suggeset that using acquire not as a context manager is an expected use case too.)
The text was updated successfully, but these errors were encountered:
I've just seen that __del__ calls release. This appears deliberate, but it does seem quite confusing. If you'd welcome it, I'd happily add a section on this to the docs.
Hi there, thanks for the package. A perhaps naive question, but the following behaviour seemed unintuitive to me. In short, if you chain method calls and don't assign the result to a variable, you don't acquire the lock. However, if you do assign the result, even to
_
, you acquire the lock. I must be missing something, but I can't tell what.A minimum reproducible example is below.
For what it's worth, I suspect the same underlying confusion causes this and #400. (#400 seems to also be a confusion about the flow, because the
acquire
method does takepolling_interval
as an argument, but it is true that__enter__
does not. Maybe the answer is, "Always useacquire
as a context manager, never antying else". If that is the answer, all fine, but it might be worth clarifying and updating the docs as current examples suggeset that usingacquire
not as a context manager is an expected use case too.)The text was updated successfully, but these errors were encountered: