-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Before getting started, ensure that you have the following prerequisites:
Python 3.7 or higher installed on your machine. Basic knowledge of Python and asynchronous programming concepts.
pip install lockapi
This command will install the necessary packages for running the code.
The LockAPIClient class allows you to create and manage locks through the Lock API.
import httpx
from aiohttp import web
import nest_asyncio
import asyncio
client = LockAPIClient(host='localhost', port=8075)
lock_id = client.acquire_lock()
client.release_lock(lock_id)
client.close_session()
The LockAPIServer class provides a server for managing locks using a REST API.
import nest_asyncio
import asyncio
from aiohttp import web
server = LockAPIServer(port=8075)
await server.start()
Make requests to the server to acquire and release locks using your preferred HTTP client (e.g., httpx, requests).
await server.stop()
Here's a complete example that demonstrates the usage of both the LockAPIClient and LockAPIServer classes:
from MyLockAPI import LockAPIClient, LockAPIServer
# Using the LockAPIServer
server = LockAPIServer(port=8075)
await server.start()
# Make requests to acquire and release locks
await server.stop()
# Using the LockAPIClient
client = LockAPIClient(host='localhost', port=8075)
lock_id = client.acquire_lock()
# Perform operations while the lock is acquired
client.release_lock(lock_id)
client.close_session()