Skip to main content

All Questions

134 votes
3 answers
125k views

What does asyncio.create_task() do?

What does asyncio.create_task() do? A bit of code that confuses me is this: import asyncio async def counter_loop(x, n): for i in range(1, n + 1): print(f"Counter {x}: {i}") ...
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 ...
1 vote
1 answer
9k views

Asyncio StreamReader occasionally reads 0 bytes

I have a simple streamreader that is listening to a TCP port for a websocket implementation. The stream occasionally reads (every 30-300 second) blank data and throws an error. loop = asyncio....
0 votes
1 answer
23 views

Asyncio: read new data from process stdout without blocking monitoring task

I write asynchronous process manager, and up till now I came up with this: import asyncio class AsyncLocalProcessManager: def __init__(self): self.process = None async def submit(...
0 votes
0 answers
39 views

Error processing SNMP request: Component value is tag-incompatible

I am trying to write a mock snmp server using pysnmp library in python. https://pypi.org/project/pysnmp/ I start the server using, python mock_snmp_server.py python --version gives Python 3.11.4 I ...
0 votes
3 answers
134 views

Converting Python socket server to Asyncio

I have already converted a multi-treaded HTTP proxy ran by a socket server into a single-treaded proxy ran by Asyncio. And, it works well for HTTP. However, when I try to reproduce the same with SSL ...
0 votes
2 answers
569 views

How to use asyncio.as_completed() with a variable size task list

Challenge Suppose I have a list L=30 tasks. Each task takes a variable time to complete and has a 10% chance of failing. If a task T fails, add the task back to a queue and prioritize it's completion. ...
70 votes
2 answers
64k views

Using queues results in asyncio exception "got Future <Future pending> attached to a different loop"

I'm trying to run this simple code with asyncio queues, but catch exceptions, and even nested exceptions. I would like to get some help with making queues in asyncio work correctly: import asyncio, ...
9 votes
1 answer
6k views

Python Asyncio errors: "OSError: [WinError 6] The handle is invalid" and "RuntimeError: Event loop is closed" [duplicate]

I am having some difficulties with properly with my code, as I get the following error after my code finishes executing while debugging on VSCode: Exception ignored in: <function ...
120 votes
10 answers
142k views

How can I periodically execute a function with asyncio?

I'm migrating from tornado to asyncio, and I can't find the asyncio equivalent of tornado's PeriodicCallback. (A PeriodicCallback takes two arguments: the function to run and the number of ...
5 votes
3 answers
11k views

asyncio multiple concurrent servers

I'm trying to use Python's asyncio to run multiple servers together, passing data between them. For my specific case I need a web server with websockets, a UDP connection to an external device, as ...
14 votes
1 answer
27k views

SQLAlchemy AttributeError: 'AsyncEngine' object has no attribute '_run_ddl_visitor'

I am trying to use the async version of SQLAlchemy in an asyncio app. However, when trying to create the tables using Metadata().create_all(), the following error occurs AttributeError: 'AsyncEngine' ...
291 votes
10 answers
393k views

Simplest async/await example possible in Python

I've read many examples, blog posts, questions/answers about asyncio / async / await in Python 3.5+, many were complex, the simplest I found was probably this one. Still it uses ensure_future, and for ...
1 vote
1 answer
4k views

Pausing Python asyncio coroutines

As my project heavily relies on asynchronous network I/O, I always have to expect some weird network error to occur: whether it is the service I'm connecting to having an API outage, or my own server ...
1 vote
1 answer
48 views

pyserial-asyncio client/server in Python 3.8 not communicating immediately

I'm learning python and asyncio and after having success with asyncio for a TCP client/server I took my first stab at creating a serial client/server using pyserial-asyncio running in bash on a ...

15 30 50 per page
1
2 3 4 5
145