pawnlib.asyncio package
from pawnlib.asyncio import *
Submodules
pawnlib.asyncio.run module
from pawnlib.asyncio import run
- class AsyncTasks(max_at_once=10, max_per_second=10, title='Working on async tasks ...', debug=False, status=False, **kwargs)[source]
Bases:
objectThis Class is to run asyncio using aiometer.
- Parameters:
max_at_once (
int, optional) – Limit maximum number of concurrently running tasks. |default|10max_per_second (
int, optional) – Limit request rate to not overload the server. |default|10title (
str, optional) – Title of the tasks |default|'Working on async tasks ...'status (
bool, optional) – Status of the tasks |default|Falsedebug (
bool, optional) – Whether to use debug |default|Falsekwargs –
Example
async_tasks = AsyncTasks(max_at_once=10, max_per_second=10) async_tasks.generate_tasks( target_list=range(1, 100) , function=run_container, **{"args": args} ).run()
- __init__(max_at_once=10, max_per_second=10, title='Working on async tasks ...', debug=False, status=False, **kwargs)[source]
This Class is to run asyncio using aiometer.
- Parameters:
max_at_once (
int, optional) – Limit maximum number of concurrently running tasks. |default|10max_per_second (
int, optional) – Limit request rate to not overload the server. |default|10title (
str, optional) – Title of the tasks |default|'Working on async tasks ...'status (
bool, optional) – Status of the tasks |default|Falsedebug (
bool, optional) – Whether to use debug |default|Falsekwargs –
Example
async_tasks = AsyncTasks(max_at_once=10, max_per_second=10) async_tasks.generate_tasks( target_list=range(1, 100) , function=run_container, **{"args": args} ).run()
- class AsyncHttp(max_at_once=10, max_per_second=10, title='Working on async tasks ...', debug=False, status=False, urls=None, **kwargs)[source]
Bases:
AsyncTasksThis class is a subclass of AsyncTasks and is used to handle asynchronous HTTP requests.
- max_at_once
Maximum number of tasks to run at once.
- Type:
int
- max_per_second
Maximum number of tasks to start per second.
- Type:
int
- title
Title for the progress bar.
- Type:
str
- debug
If True, print debug information.
- Type:
bool
- status
If True, print status information.
- Type:
bool
- urls
List of URLs to fetch.
- Type:
list
This Class is to run asyncio using aiometer.
- Parameters:
max_at_once (
int, optional) – Limit maximum number of concurrently running tasks. |default|10max_per_second (
int, optional) – Limit request rate to not overload the server. |default|10title (optional) – Title of the tasks |default|
'Working on async tasks ...'status (
bool, optional) – Status of the tasks |default|Falsedebug (
bool, optional) – Whether to use debug |default|Falsekwargs –
Example
async_tasks = AsyncTasks(max_at_once=10, max_per_second=10) async_tasks.generate_tasks( target_list=range(1, 100) , function=run_container, **{"args": args} ).run()
- async fetch_httpx_url(url, method='get', timeout=4, info='', max_keepalive_connections=10, max_connections=20, **kwargs)[source]
Asynchronously fetch a URL using httpx.
- Parameters:
url (str) – The URL to fetch.
method (str) – The HTTP method to use. Default is “get”. |default|
'get'timeout (int) – The timeout for the request in seconds. Default is 4. |default|
4info (str) – Additional information for the request. Default is an empty string. |default|
''max_keepalive_connections (int) – The maximum number of keep-alive connections. Default is 10. |default|
10max_connections (int) – The maximum number of connections. Default is 20. |default|
20**kwargs – Additional keyword arguments for the httpx request.
- Returns:
The response from the server, or an empty dictionary if an error occurred.
- Return type:
httpx.Response or dict
pawnlib.asyncio.async_helper module
from pawnlib.asyncio import async_helper
- async shutdown_async_tasks(loop=None, tasks=None, logger=None, exit_on_shutdown=True, verbose=1, exit_code=0)[source]
Shutdown all pending async tasks and close the loop gracefully.
- Parameters:
loop (asyncio.AbstractEventLoop) – The event loop to use. If None, the current running loop will be used. |default|
Nonetasks (List[asyncio.Task]) – List of tasks to cancel. If None, all pending tasks in the loop will be cancelled. |default|
Nonelogger (logging.Logger) – Logger instance for logging. If None, print will be used as fallback. |default|
Noneexit_on_shutdown (bool) – If True, the system will exit after shutdown. |default|
Trueverbose (int) – The verbosity level for logging output. |default|
1exit_code (int) – Exit code to return when exiting the system (default is 0). |default|
0