Skip to main content

All 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 ...
Rajan Chauhan's user avatar
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 ...
Sergio Ivanuzzo's user avatar
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 ...
Riley Hughes's user avatar
  • 1,484
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 ...
Bailey Parker's user avatar
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. ...
SangminKim's user avatar
  • 9,176
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 ...
Pawel Miech's user avatar
  • 7,822
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 ...
J doe's user avatar
  • 81
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 ...
fenriskiba's user avatar
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 ...
Goodies's user avatar
  • 4,701
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 ...
Paul's user avatar
  • 6,777
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 ...
Paul's user avatar
  • 6,777
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 ...
Berislav Lopac's user avatar
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 ...
balki's user avatar
  • 27.7k
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 ...
Ahmet DAL's user avatar
  • 4,702
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?
Jason's user avatar
  • 2,304

15 30 50 per page