-
Notifications
You must be signed in to change notification settings - Fork 10
Closed
Description
I can't define connection and start functions without running the event loop.
if PY_37:
__get_running_loop = asyncio.get_running_loop # by the reason you can't use the module without a running event loopI want the connection variable to be global and access functions from other modules while the event loop is not running yet
conn = asynctnt.Connection(host='127.0.0.1', port=3301)
At the moment I have to make a crutch out of the initial function:
async def init_conn():
global conn
conn = asynctnt.Connection(host='127.0.0.1', port=3301)
await asyncio.sleep(0)so that I can access functions from other modules.
the full example which doesn't work without a crutch:
import asyncio
import asynctnt
conn = asynctnt.Connection(host='127.0.0.1', port=3301)
async def insert(space: str, data, replace=False):
if not conn.is_connected:
await conn.connect()
result = await conn.insert(space, list(data), replace=replace)
return result[0] if len(result) == 1 else result
async def update(space: str, key, ops):
if not conn.is_connected:
await conn.connect()
key = [key] if type(key) is not list else key
result = await conn.update(space, key, ops)
return result[0] if len(result) > 0 else None
async def select(space: str, key=None, index='primary', unpack=True):
if not conn.is_connected:
await conn.connect()
key = [key] if type(key) is not list and key else key
result = await conn.select(space, key=key, index=index)
return result[0] if len(result) == 1 and unpack else result
async def sql(query, args=None, parse_metadata=False):
if not conn.is_connected:
await conn.connect()
result = await conn.sql(query, args, parse_metadata=parse_metadata)
return result
async def delete(space: str, key):
if not conn.is_connected:
await conn.connect()
key = [key] if type(key) is not list else key
await conn.delete(space, key)Metadata
Metadata
Assignees
Labels
No labels