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

MountLock context manager (was: Exception handling in mount/unmount; Enable lint check W0706) #1799

Draft
wants to merge 7 commits into
base: dev
Choose a base branch
from

Conversation

feman323
Copy link
Contributor

W0706 complains if an Exception is directly raised back without any handling. First I wanted to remove the try / catch blocks completely, but the I've seen that there are also "finally" statements. Therefore I just added some logging, which caused the lint check to run successful.

@buhtz
Copy link
Member

buhtz commented Jul 17, 2024

Hi Manual,
thank your for this contribution. I would set this as draft because it needs further investigation and resources.
Your solution might silence the linter but does not improve the quality of code or BIT behavior. The log output is polluted without any reason.

There is more wrong then just a not handled exception. On a quick view I would assume that the goal of this code construct was that the code block in finally will be executed no matter if there is an exception or not. It might have been the only way in older Python versions but not in today Python.

Today you would solve something like this with a context manager.

But I am not sure at all and would need some time to dive into it.

Best,
Christian

As an example you see here that the exception is re-raised but finally is also executed.

>>> try:
...   x = 7 / 0
... except Exception:
...    raise
... finally:
...   print('FF')
... 
FF
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
ZeroDivisionError: division by zero
>>> 

@buhtz buhtz added the Code Quality About code quality, refactoring, (unit) testing, linting, ... label Jul 17, 2024
@buhtz buhtz added this to the 2nd release from now milestone Jul 17, 2024
@buhtz buhtz marked this pull request as draft July 17, 2024 13:34
@buhtz buhtz changed the title Enable lint check W0706 Enable lint check W0706 (refactor exception handling in mount/unmount; implement MountLock context manager) Jul 17, 2024
@buhtz buhtz assigned buhtz and unassigned buhtz Jul 17, 2024
@feman323
Copy link
Contributor Author

Hi Christian,

Okay, I will try to embed this in a context manager.

Regards,

Manuel

@feman323 feman323 marked this pull request as ready for review July 23, 2024 07:30
@buhtz buhtz added the PR: Modifications requested Maintenance team requested modifications and waiting for their implementation label Aug 11, 2024
@buhtz buhtz marked this pull request as draft August 11, 2024 15:23
@buhtz
Copy link
Member

buhtz commented Aug 14, 2024

Please have a look if our (quit fresh) flock module and its base class _FlockContext might help you. I am assuming that base class need to be modified somehow to be more flexible.

@buhtz
Copy link
Member

buhtz commented Sep 16, 2024

My advice would be to extract the five methods mountLock*() and mountProcess*() into something else. A context manager class for example.

@buhtz buhtz removed the Code Quality About code quality, refactoring, (unit) testing, linting, ... label Sep 16, 2024
@buhtz buhtz changed the title Enable lint check W0706 (refactor exception handling in mount/unmount; implement MountLock context manager) MountLock context manager (was: Exception handling in mount/unmount; Enable lint check W0706) Sep 16, 2024
@feman323
Copy link
Contributor Author

feman323 commented Oct 8, 2024

Hello Christian,

Sorry for the late response. At the moment, I don't have much time to work on this PR.

I have one question: Does it make sense to extract the mountLock methods into a context manager? The process lock prevents other processes from making changes at the same time and should always be removed after execution, so I understand why a context manager makes sense in this case.

However, the mountLock, on the other hand, should only be created / removed if the folder was successfully mounted / unmounted. So the methods calls for creating / removing the lock can be placed at the end of the mount / umount methods without the need for a context manager. Or am I missing something?

@buhtz
Copy link
Member

buhtz commented Oct 9, 2024

Hello Manuel,

At the moment, I don't have much time to work on this PR.

That is OK. I just need to know.

I have one question: Does it make sense ...

However, the mountLock, on the other hand...

I don't have an answer or opinion about it. I am not deep enough into that topic. But me or someone else will consider your comment when picking up this PR again.

Best,
Christian

@buhtz
Copy link
Member

buhtz commented Nov 23, 2024

Hello Manuel,
I got deeper in the related code around mount locking to better understand how it works and what it does. In PR #1942 I added some unit tests and refactored code.

The mounting is a very sensible and important part of the BIT codebase. There is too much going on under the hood and I am still not able to estimate the implications for our users. Taking risk-benefit calculation of your PR into account I can sleep better if we don't merge.

My apologize for this.

Keep in mind that your work is not waste. It triggered some other actions (e.g. PR #1942 ) improving BIT. So thank you for this.

Regards,
Christian

@buhtz buhtz added Discussion decision or consensus needed Feedback needs user response, may be closed after timeout without a response and removed PR: Modifications requested Maintenance team requested modifications and waiting for their implementation labels Nov 23, 2024
buhtz added a commit that referenced this pull request Nov 23, 2024
Related to PR #1799. Thank you to Manual for inspiring this PR.
@buhtz buhtz added the PR: Unlikely to merge PR is unlikely to be merged due to project goals, technical limitations, or other constraints. label Nov 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Discussion decision or consensus needed Feedback needs user response, may be closed after timeout without a response PR: Unlikely to merge PR is unlikely to be merged due to project goals, technical limitations, or other constraints.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants