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

init: Add timeout when locking mapset, add locking to Python API #5443

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

wenzeslaus
Copy link
Member

This change introduces two things:

  1. Timeout parameter in CLI which is enabled by default and makes GRASS wait if the mapset is locked.
  2. Lock parameter to the grass.script.setup.init function so that Python API can now lock the mapset if desired.

Additionally, this syncs locking parameters and underlying code between CLI and Python API so both timeout and forcible removal of lock are available in Python as well. The tests are using the Python API.

Locked mapset example in CLI:

$ grass ~/grassdata/nc_spm_08_grass7/user1/
Starting GRASS GIS...
Mapset <.../nc_spm_08_grass7/user1> locked (attempt 1), but will retry in 1.00 seconds...
Mapset <.../nc_spm_08_grass7/user1> locked (attempt 2), but will retry in 2.00 seconds...
Mapset <.../nc_spm_08_grass7/user1> locked (attempt 3), but will retry in 4.00 seconds...

Lock in Python (also works as a context manager):

import grass.script as gs
s = gs.setup.init("~/grassdata/nc_spm_08_grass7/user1/", lock=True, timeout=0)
s.finish()

This also introduces an experimental execution of the grass.app with CLI API using python -m grass.app. Specifically, lock and unlock subcommands are now available and can be used for testing, fixing lock situations, and by external applications which need to persistently lock mapset without using the Python API directly.

Example lock-unlock (path to Python packages needs to be setup, don't ask me why LD_LIBRARY_PATH does not need to be setup - it is needed for test of the Python API):

export PYTHONPATH="$(.../bin.x86_64-pc-linux-gnu/grass --config python-path)"
python -m grass.app lock ~/grassdata/nc_spm_08_grass7/user1/
python -m grass.app unlock ~/grassdata/nc_spm_08_grass7/user1/

@wenzeslaus wenzeslaus added the enhancement New feature or request label Mar 25, 2025
@wenzeslaus wenzeslaus added this to the 8.5.0 milestone Mar 25, 2025
@github-actions github-actions bot added Python Related code is in Python libraries docs markdown Related to markdown, markdown files tests Related to Test Suite labels Mar 25, 2025
@wenzeslaus
Copy link
Member Author

I need to fix the tests...there is no locking on Windows. Otherwise the tests pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs enhancement New feature or request libraries markdown Related to markdown, markdown files Python Related code is in Python tests Related to Test Suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant