Skip to main content

lockable resource module

Project description

lockable

CircleCI PyPI version Coverage Status

Resource locking module for python.

Originally designed for following projects:

Module provides python API and simple CLI interface.

Resource is released in following cases:

  • process ends
  • when context ends when lockable.auto_lock(..) is used
  • allocation.unlock() is called
  • lockable.unlock() is called

Resources data provider support following mechanisms:

  • resources.json file in file system
  • python list of dictionaries
  • http uri which points to API and is used with HTTP GET method. API should provide resources.json data as json object.

CLI interface

% lockable --help
usage: lockable [-h] [--validate-only] [--lock-folder LOCK_FOLDER] [--resources RESOURCES]
                [--timeout TIMEOUT] [--hostname HOSTNAME]
                [--requirements REQUIREMENTS]
                [command [command ...]]

run given command while suitable resource is allocated.
Usage example: lockable --requirements {"online":true} echo using resource: $ID

positional arguments:
  command               Command to be execute during device allocation

optional arguments:
  -h, --help            show this help message and exit
  --validate-only       Only validate resources.json
  --lock-folder LOCK_FOLDER
                        lock folder
  --resources RESOURCES
                        Resources file (utf-8) or http uri
  --timeout TIMEOUT     Timeout for trying allocate suitable resource
  --hostname HOSTNAME   Hostname
  --requirements REQUIREMENTS
                        requirements as json string

API's

Constructor

lockable = Lockable([hostname], [resource_list_file], [resource_list], [lock_folder])

Allocation

allocation_context = lockable.lock(requirements, [timeout_s])
print(allocation_context.resource_info)
print(allocation_context.resource_id)
allocation_context.unlock()
# or using resource info
lockable.unlock(allocation_context)

Allocation context contains following API:

  • requirements: dict Original requirements for allocation
  • resource_info: dict Allocated resource information
  • unlock(): func release resource lock function
  • allocation_queue_time: timedelta How long waited before allocation
  • allocation_start_time: datetime when allocation was started
  • release_time: datetime when allocation was ended
  • alloc_id: str allocation id
  • allocation_durations: timedelta how long time allocation takes

or using context manager which unlock automatically

with lockable.auto_lock(requirements, [timeout_s]) as allocation:
    print(allocation.resource_info)

Tips:

You can allocate also offline devices by set requirements "online": None . You can ignore also hostname same same way by setting it to None`

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lockable-0.11.1.tar.gz (24.0 kB view details)

Uploaded Source

Built Distribution

lockable-0.11.1-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

File details

Details for the file lockable-0.11.1.tar.gz.

File metadata

  • Download URL: lockable-0.11.1.tar.gz
  • Upload date:
  • Size: 24.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.8.12

File hashes

Hashes for lockable-0.11.1.tar.gz
Algorithm Hash digest
SHA256 e75a45466e8484413ac0d78bb15529fa46e49d4296abe371359db57f6cfa2619
MD5 073837e7db3f5d576924132150a1a06d
BLAKE2b-256 5973f737a5e57d01b8c3c362adcd7de296362b251b3d5949da66aa95ae276426

See more details on using hashes here.

File details

Details for the file lockable-0.11.1-py3-none-any.whl.

File metadata

  • Download URL: lockable-0.11.1-py3-none-any.whl
  • Upload date:
  • Size: 13.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.8.12

File hashes

Hashes for lockable-0.11.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ce5ae1e9bdbecba33c26c1cf7e0618c9f80f3a147fb598cb015283d48ed2db8f
MD5 925dff190756a28a14657e243f684212
BLAKE2b-256 b4e393bc23e87bd584457aaebc50af1b6a3136fcc217cc270daad05a87044c03

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page