Mapepire-IBMi / mapepire-python

python client for mapepire
Apache License 2.0
4 stars 2 forks source link

Feature/pool #53

Closed ajshedivy closed 3 weeks ago

ajshedivy commented 3 weeks ago

Fixes #

Changes proposed in this pull request:

Async usage:


import asyncio
from mapepire_python.pool.pool_job import PoolJob
from mapepire_python.types import DaemonServer

creds = DaemonServer(
    host=server,
    port=port,
    user=user,
    password=password,
    ignoreUnauthorized=True,
)

async def main():
    async with PoolJob(creds=creds) as job:
        query = job.query('select * from sample.employee')
        res = await query.run()
        assert res['success'] == True

if __name__ == '__main__':
    asyncio.run(main())

Pool usage

import asyncio
from mapepire_python.pool.pool_client import Pool, PoolOptions
from mapepire_python.types import DaemonServer

creds = DaemonServer(
    host=server,
    port=port,
    user=user,
    password=password,
    ignoreUnauthorized=True,
)

async def main():
    pool = Pool(
        options=PoolOptions(
            creds=creds,
            opts=None,
            max_size=5,
            starting_size=3
        )
    )
    await pool.init()

    job_names = []
    resultsA = await asyncio.gather(
        pool.execute('values (job_name)'),
        pool.execute('values (job_name)'),
        pool.execute('values (job_name)')
    )
    job_names = [res['data'][0]['00001'] for res in resultsA]

    assert len(job_names) == 3

    assert pool.get_active_job_count() == 3

if __name__ == '__main__':
    asyncio.run(main())

Before submitting

worksofliam commented 3 weeks ago

Looks like the tests are passing but it did log one huge warning:

Click me ``` (.venv) barry@Liams-MBP mapepire-python % pytest tests/ /Users/barry/Repos/mapepire/mapepire-python/.venv/lib/python3.12/site-packages/pytest_asyncio/plugin.py:208: PytestDeprecationWarning: The configuration option "asyncio_default_fixture_loop_scope" is unset. The event loop scope for asynchronous fixtures will default to the fixture caching scope. Future versions of pytest-asyncio will default the loop scope for asynchronous fixtures to function scope. Set the default fixture loop scope explicitly in order to avoid unexpected behavior in the future. Valid fixture loop scopes are: "function", "class", "module", "package", "session" warnings.warn(PytestDeprecationWarning(_DEFAULT_FIXTURE_LOOP_SCOPE_UNSET)) ====================================================== test session starts ====================================================== platform darwin -- Python 3.12.4, pytest-8.3.2, pluggy-1.5.0 rootdir: /Users/barry/Repos/mapepire/mapepire-python/tests configfile: pytest.ini plugins: asyncio-0.24.0, env-1.1.3 asyncio: mode=Mode.STRICT, default_loop_scope=None collected 59 items tests/async_pool_test.py ..................... [ 35%] tests/cl_test.py ... [ 40%] tests/pooling_test.py ........ [ 54%] tests/query_manager_test.py ..... [ 62%] tests/simple_test.py .... [ 69%] tests/sql_test.py .................. [100%] ======================================================= warnings summary ======================================================== pooling_test.py::test_pool_with_no_space_but_ready_job_returns_ready_job /Users/barry/Repos/mapepire/mapepire-python/.venv/lib/python3.12/site-packages/_pytest/unraisableexception.py:85: PytestUnraisableExceptionWarning: Exception ignored in: Traceback (most recent call last): File "/opt/homebrew/Cellar/python@3.12/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/sslproto.py", line 88, in __init__ def __init__(self, loop, ssl_protocol): RuntimeError: coroutine ignored GeneratorExit warnings.warn(pytest.PytestUnraisableExceptionWarning(msg)) -- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html =========================================== 59 passed, 1 warning in 66.52s (0:01:06) ============================================ Task was destroyed but it is pending! task: wait_for= cb=[Task.task_wakeup(), _wait.._on_completion() at /opt/homebrew/Cellar/python@3.12/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/tasks.py:534]> Task was destroyed but it is pending! task: wait_for=> Task was destroyed but it is pending! task: wait_for= wait_for= cb=[Task.task_wakeup(), _wait.._on_completion() at /opt/homebrew/Cellar/python@3.12/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/tasks.py:534]>> Exception ignored in: Traceback (most recent call last): File "/Users/barry/Repos/mapepire/mapepire-python/.venv/lib/python3.12/site-packages/websockets/legacy/protocol.py", line 1325, in close_connection await self.close_transport() File "/Users/barry/Repos/mapepire/mapepire-python/.venv/lib/python3.12/site-packages/websockets/legacy/protocol.py", line 1343, in close_transport if await self.wait_for_connection_lost(): ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/barry/Repos/mapepire/mapepire-python/.venv/lib/python3.12/site-packages/websockets/legacy/protocol.py", line 1366, in wait_for_connection_lost async with asyncio_timeout(self.close_timeout): ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/Cellar/python@3.12/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/timeouts.py", line 145, in timeout loop = events.get_running_loop() ^^^^^^^^^^^^^^^^^^^^^^^^^ RuntimeError: no running event loop Task was destroyed but it is pending! task: wait_for=> Task was destroyed but it is pending! task: wait_for= cb=[Task.task_wakeup(), _wait.._on_completion() at /opt/homebrew/Cellar/python@3.12/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/tasks.py:534]> Task was destroyed but it is pending! task: wait_for=> Task was destroyed but it is pending! task: wait_for= wait_for= cb=[Task.task_wakeup(), _wait.._on_completion() at /opt/homebrew/Cellar/python@3.12/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/tasks.py:534]>> Exception ignored in: Traceback (most recent call last): File "/Users/barry/Repos/mapepire/mapepire-python/.venv/lib/python3.12/site-packages/websockets/legacy/protocol.py", line 1325, in close_connection File "/Users/barry/Repos/mapepire/mapepire-python/.venv/lib/python3.12/site-packages/websockets/legacy/protocol.py", line 1343, in close_transport File "/Users/barry/Repos/mapepire/mapepire-python/.venv/lib/python3.12/site-packages/websockets/legacy/protocol.py", line 1366, in wait_for_connection_lost File "/opt/homebrew/Cellar/python@3.12/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/timeouts.py", line 145, in timeout RuntimeError: no running event loop Task was destroyed but it is pending! task: wait_for=> Task was destroyed but it is pending! task: wait_for= cb=[Task.task_wakeup(), _wait.._on_completion() at /opt/homebrew/Cellar/python@3.12/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/tasks.py:534]> Task was destroyed but it is pending! task: wait_for=> Task was destroyed but it is pending! task: wait_for= wait_for= cb=[Task.task_wakeup(), _wait.._on_completion() at /opt/homebrew/Cellar/python@3.12/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/tasks.py:534]>> Exception ignored in: Traceback (most recent call last): File "/Users/barry/Repos/mapepire/mapepire-python/.venv/lib/python3.12/site-packages/websockets/legacy/protocol.py", line 1325, in close_connection File "/Users/barry/Repos/mapepire/mapepire-python/.venv/lib/python3.12/site-packages/websockets/legacy/protocol.py", line 1343, in close_transport File "/Users/barry/Repos/mapepire/mapepire-python/.venv/lib/python3.12/site-packages/websockets/legacy/protocol.py", line 1366, in wait_for_connection_lost File "/opt/homebrew/Cellar/python@3.12/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/timeouts.py", line 145, in timeout RuntimeError: no running event loop Task was destroyed but it is pending! task: wait_for=> Task was destroyed but it is pending! task: wait_for= cb=[Task.task_wakeup(), _wait.._on_completion() at /opt/homebrew/Cellar/python@3.12/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/tasks.py:534]> Task was destroyed but it is pending! task: wait_for=> Task was destroyed but it is pending! task: wait_for= wait_for= cb=[Task.task_wakeup(), _wait.._on_completion() at /opt/homebrew/Cellar/python@3.12/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/tasks.py:534]>> Exception ignored in: Traceback (most recent call last): File "/Users/barry/Repos/mapepire/mapepire-python/.venv/lib/python3.12/site-packages/websockets/legacy/protocol.py", line 1325, in close_connection File "/Users/barry/Repos/mapepire/mapepire-python/.venv/lib/python3.12/site-packages/websockets/legacy/protocol.py", line 1343, in close_transport File "/Users/barry/Repos/mapepire/mapepire-python/.venv/lib/python3.12/site-packages/websockets/legacy/protocol.py", line 1366, in wait_for_connection_lost File "/opt/homebrew/Cellar/python@3.12/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/timeouts.py", line 145, in timeout RuntimeError: no running event loop Task was destroyed but it is pending! task: wait_for=> Task was destroyed but it is pending! task: wait_for= cb=[Task.task_wakeup(), _wait.._on_completion() at /opt/homebrew/Cellar/python@3.12/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/tasks.py:534]> Task was destroyed but it is pending! task: wait_for=> Task was destroyed but it is pending! task: wait_for= wait_for= cb=[Task.task_wakeup(), _wait.._on_completion() at /opt/homebrew/Cellar/python@3.12/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/tasks.py:534]>> Task was destroyed but it is pending! task: wait_for= cb=[Task.task_wakeup(), _wait.._on_completion() at /opt/homebrew/Cellar/python@3.12/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/tasks.py:534]> Task was destroyed but it is pending! task: wait_for=> Task was destroyed but it is pending! task: wait_for= wait_for= cb=[Task.task_wakeup(), _wait.._on_completion() at /opt/homebrew/Cellar/python@3.12/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/tasks.py:534]>> Exception ignored in: Traceback (most recent call last): File "/Users/barry/Repos/mapepire/mapepire-python/.venv/lib/python3.12/site-packages/websockets/legacy/protocol.py", line 1325, in close_connection File "/Users/barry/Repos/mapepire/mapepire-python/.venv/lib/python3.12/site-packages/websockets/legacy/protocol.py", line 1343, in close_transport File "/Users/barry/Repos/mapepire/mapepire-python/.venv/lib/python3.12/site-packages/websockets/legacy/protocol.py", line 1366, in wait_for_connection_lost File "/opt/homebrew/Cellar/python@3.12/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/timeouts.py", line 145, in timeout RuntimeError: no running event loop Exception ignored in: Traceback (most recent call last): File "/Users/barry/Repos/mapepire/mapepire-python/.venv/lib/python3.12/site-packages/websockets/legacy/protocol.py", line 1325, in close_connection File "/Users/barry/Repos/mapepire/mapepire-python/.venv/lib/python3.12/site-packages/websockets/legacy/protocol.py", line 1343, in close_transport File "/Users/barry/Repos/mapepire/mapepire-python/.venv/lib/python3.12/site-packages/websockets/legacy/protocol.py", line 1366, in wait_for_connection_lost File "/opt/homebrew/Cellar/python@3.12/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/timeouts.py", line 145, in timeout RuntimeError: no running event loop Task was destroyed but it is pending! task: wait_for=> Task was destroyed but it is pending! task: wait_for=> Task was destroyed but it is pending! task: wait_for= cb=[Task.task_wakeup(), _wait.._on_completion() at /opt/homebrew/Cellar/python@3.12/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/tasks.py:534]> Task was destroyed but it is pending! task: wait_for=> Task was destroyed but it is pending! task: wait_for= wait_for= cb=[Task.task_wakeup(), _wait.._on_completion() at /opt/homebrew/Cellar/python@3.12/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/tasks.py:534]>> Task was destroyed but it is pending! task: wait_for= cb=[Task.task_wakeup(), _wait.._on_completion() at /opt/homebrew/Cellar/python@3.12/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/tasks.py:534]> Task was destroyed but it is pending! task: wait_for=> Task was destroyed but it is pending! task: wait_for= wait_for= cb=[Task.task_wakeup(), _wait.._on_completion() at /opt/homebrew/Cellar/python@3.12/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/tasks.py:534]>> Exception ignored in: Traceback (most recent call last): File "/Users/barry/Repos/mapepire/mapepire-python/.venv/lib/python3.12/site-packages/websockets/legacy/protocol.py", line 1325, in close_connection File "/Users/barry/Repos/mapepire/mapepire-python/.venv/lib/python3.12/site-packages/websockets/legacy/protocol.py", line 1343, in close_transport File "/Users/barry/Repos/mapepire/mapepire-python/.venv/lib/python3.12/site-packages/websockets/legacy/protocol.py", line 1366, in wait_for_connection_lost File "/opt/homebrew/Cellar/python@3.12/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/timeouts.py", line 145, in timeout RuntimeError: no running event loop Exception ignored in: Traceback (most recent call last): File "/Users/barry/Repos/mapepire/mapepire-python/.venv/lib/python3.12/site-packages/websockets/legacy/protocol.py", line 1325, in close_connection File "/Users/barry/Repos/mapepire/mapepire-python/.venv/lib/python3.12/site-packages/websockets/legacy/protocol.py", line 1343, in close_transport File "/Users/barry/Repos/mapepire/mapepire-python/.venv/lib/python3.12/site-packages/websockets/legacy/protocol.py", line 1366, in wait_for_connection_lost File "/opt/homebrew/Cellar/python@3.12/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/timeouts.py", line 145, in timeout RuntimeError: no running event loop Task was destroyed but it is pending! task: wait_for=> Task was destroyed but it is pending! task: wait_for=> ```