quart

RuntimeError: Task got Future <Future pending> attached to a different loop

北城以北 提交于 2019-12-20 07:39:33
问题 How to call async method which get event loop in main thread inside another async method in Quart? t.py from telethon import TelegramClient, functions, types client2 = TelegramClient(sn, api_id, api_hash).start() async def create_contact(): return await client2(functions.contacts.ImportContactsRequest([ types.InputPhoneContact(0, '8', 'first_name', 'last_name') ])) app.py from quart import Quart, websocket,render_template,request import t2 app = Quart(__name__) @app.route('/wa2tg') def wa2tg(

Websockets with the python web framework “quart”?

為{幸葍}努か 提交于 2019-12-11 04:57:13
问题 I need help with the python web frame work, Quart, more specifically the websockets. I would like to be able to register a client when it connects (add it to a python list), and unregister them (remove it from the python list) when it disconnects. The closest thing I could find on the web is this code: connected = set() async def handler(websocket, path): global connected # Register. connected.add(websocket) try: # Implement logic here. await asyncio.wait([ws.send("Hello!") for ws in

How to obtain an event loop from Quart

心已入冬 提交于 2019-12-06 07:23:12
问题 Hello I fairly new to Python and I am trying to convert an existing application I have on Flask into Quart (https://gitlab.com/pgjones/quart) which is supposed to be built on top of asyncio, so I can use Goblin OGM to interact with JanusGraph or TinkerPop. According to the examples I found on Goblin I need to obtain an event loop to run the commands asynchronously. >>> import asyncio >>> from goblin import Goblin >>> loop = asyncio.get_event_loop() >>> app = loop.run_until_complete( ...

How to obtain an event loop from Quart

最后都变了- 提交于 2019-12-04 12:23:22
Hello I fairly new to Python and I am trying to convert an existing application I have on Flask into Quart ( https://gitlab.com/pgjones/quart ) which is supposed to be built on top of asyncio, so I can use Goblin OGM to interact with JanusGraph or TinkerPop. According to the examples I found on Goblin I need to obtain an event loop to run the commands asynchronously. >>> import asyncio >>> from goblin import Goblin >>> loop = asyncio.get_event_loop() >>> app = loop.run_until_complete( ... Goblin.open(loop)) >>> app.register(Person, Knows) However I can't find a way to obtain the event loop

RuntimeError: Task got Future <Future pending> attached to a different loop

一世执手 提交于 2019-12-02 13:11:05
How to call async method which get event loop in main thread inside another async method in Quart? t.py from telethon import TelegramClient, functions, types client2 = TelegramClient(sn, api_id, api_hash).start() async def create_contact(): return await client2(functions.contacts.ImportContactsRequest([ types.InputPhoneContact(0, '8', 'first_name', 'last_name') ])) app.py from quart import Quart, websocket,render_template,request import t2 app = Quart(__name__) @app.route('/wa2tg') def wa2tg(): return render_template('wa2tg.html',nm=request.args.get('nm','')) @app.websocket('/wa2tg2') async