All Questions
28 questions
1
vote
0
answers
730
views
Python asyncio with multiple long running task producing no event loop error
I am currently working on a script for some web scraping related activity and recently decided to move to asyncio on python 3.5.2 version.
There are 3 coroutines producer, processor and consumer each ...
1
vote
1
answer
2k
views
Python3 and asyncio: how to implement websocket server as asyncio instance?
I have multiple servers, each server is instance returning by asyncio.start_server. I need my web_server to works with websockets, to have possibility getting data using my javascript client. As I can ...
3
votes
1
answer
9k
views
Using async/await keywords with Tk.after() method of tkinter
I am creating a cryptocurrency exchange API client using Python3.5 and Tkinter. I have several displays that I want to update asynchronously every 10 seconds. I am able to update the displays every 10 ...
4
votes
1
answer
741
views
Why does asyncio subprocess behave differently with created event loop unless you set_event_loop?
I have this simple async code that spawns sleep 3 and then waits for it to complete:
from asyncio import SelectorEventLoop, create_subprocess_exec, \
wait_for, get_event_loop, set_event_loop
def ...
9
votes
1
answer
10k
views
Exception " There is no current event loop in thread 'MainThread' " while running over new loop
The is the simple test code and the result.
import asyncio
async def test():
await asyncio.sleep(1)
if __name__ == '__main__':
asyncio.set_event_loop(None) # Clear the main loop.
...
14
votes
2
answers
16k
views
How to set up logging for aiohttp.client when making request with aiohttp.ClientSession()?
I have some code making sequence of requests to some API. I'd like to set up common logging for all, how can I set this up?
Let's say my code looks like this
import aiohttp
import asyncio
async ...
7
votes
2
answers
4k
views
How to use asyncio event loop in library function
I'm trying to create a function performing some asynchronous operations using asyncio, users of this function should not need to know that asyncio is involved under the hood.
I'm having a very hard ...
2
votes
1
answer
2k
views
Call Async Functions Dynamically with exec()
So, I'm implementing a Discord Bot using discord.py, and I'm trying to dynamically call functions based on commands. I was able to test dynamic function calls with exec() fine, but they seem to fall ...
7
votes
3
answers
1k
views
How can I change this code to use context managers?
I'm trying to log into a website simultaneously using multiple credentials with aiohttp and asyncio. In the create_tasks function, I generate a list of sessions to be used for each. The reason I ...
1
vote
1
answer
2k
views
How to make object awaitable in python 3.5?
I have a pseudo async generator which actually fetches all needed data on the initialisation. And I want to iterate over it with async for. My simplified code looks like this:
class MyObject:
def ...
4
votes
2
answers
2k
views
Test calling a python coroutine (async def) from a regular function
Let's say I have some asyncio coroutine which fetches some data and returns it. Like this:
async def fetch_data(*args):
result = await some_io()
return result
Basically this coroutine is called ...
1
vote
1
answer
1k
views
Running asyncio.subprocess.Process from Tornado RequestHandler
I'm trying to write a Tornado web app which runs a local command asynchronously, as a coroutine. This is the stripped down example code:
#! /usr/bin/env python3
import shlex
import asyncio
import ...
68
votes
4
answers
49k
views
How to use asyncio with existing blocking library?
I have a few blocking functions foo, bar and I can't change those (Some internal library I don't control. Talks to one or more network services). How do I use it as async? E.g. I want to do the ...
0
votes
0
answers
756
views
asyncio - Catch timeout for asyncio.wait
I am using asyncio with python3.5.1 and I have a utility function that makes sync methods to async ones. I pass multiple blocking functions and wait for their results for a timeout. I use timeout ...
58
votes
4
answers
27k
views
@asyncio.coroutine vs async def
With the asyncio library I've seen,
@asyncio.coroutine
def function():
...
and
async def function():
...
used interchangeably.
Is there any functional difference between the two?