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(<allocation>) 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
  --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 = lockable.lock(requirements, [timeout_s])
print(allocation.resource_info)
print(allocation.resource_id)
allocation.unlock()
# or using resource info
lockable.unlock(allocation)

or using context manager which unlock automatically

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

Project details


Download files

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

Files for lockable, version 0.5.0
Filename, size File type Python version Upload date Hashes
Filename, size lockable-0.5.0-py3-none-any.whl (11.7 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size lockable-0.5.0.tar.gz (15.3 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page