-
Notifications
You must be signed in to change notification settings - Fork 452
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
Use the filelock library to determine the primary GUI/Core process #7660
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fd9d30b
to
5174810
Compare
drew2a
reviewed
Nov 3, 2023
drew2a
reviewed
Nov 3, 2023
drew2a
reviewed
Nov 3, 2023
drew2a
reviewed
Nov 3, 2023
drew2a
reviewed
Nov 3, 2023
drew2a
reviewed
Nov 3, 2023
drew2a
reviewed
Nov 3, 2023
drew2a
reviewed
Nov 3, 2023
drew2a
reviewed
Nov 3, 2023
drew2a
reviewed
Nov 3, 2023
drew2a
suggested changes
Nov 3, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR looks good to me.
I have a minor question about the naming and a request for optionally adding descriptions for the tests (otherwise, it can be hard to guess what specific tests are testing).
As a side note, the test coverage for this PR could be increased.
drew2a
approved these changes
Nov 6, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR provides an alternative way (as compared to #7637) to determine the primary Tribler process. This PR uses the
filelock
library for that purpose:'tribler-gui.lock'
/'tribler-core.lock'
are created and held until the related GUI/Core process is finished.The typical usage of the new API looks the following way:
First, the process tries to acquire the file lock:
If the attempt to grab the lock is successful, the process is considered a primary process; otherwise, it is a secondary process and should terminate after passing the magnet link to the primary process.
The current process should hold the lock object returned from the
try_acquire_file_lock
call until the process finishes, as the lock releases if the lock object is garbage collected. The process can doprocess_lock.release()
before it finishes, but it is not necessary, as (1) the object will be garbage collected after the program exits the scope where the lock was declared, and (2) even if the lock file was not removed from the disk, the lock is still considered as released after the current process is finished. On Linux, the lock file is not always deleted at the end because of the details of how Linux works with open file descriptors, but it is not a problem.The
ProcessManager
is initialized so the current process (primary or secondary) can store information about itself in the database:The process should check whether the attempt to grab the lock was successful, and if not, it should terminate:
So, the API is relatively simple.