Questions tagged [nest-asyncio]

18 questions
9
votes
2 answers

Caching results in an async environment

I am working in a FastAPI endpoint that make a I/O bound operation, which is async for efficiency. However, it takes time, so I would like to cache the results to reuse it for a period of time. I currently I have this: from fastapi import…
Nicolas Martinez
  • 719
  • 1
  • 6
  • 23
2
votes
2 answers

jupyter notebooks-safe asyncio run wrapper method for a library

I'm building a library that leverages asyncio internally. While the user shouldn't be aware of it, the internal implementation currently wraps the async code with the asyncio.run() porcelain wrapper. However, some users will be executing this…
Joey Baruch
  • 4,180
  • 6
  • 34
  • 48
2
votes
1 answer

Workflow cannot be stoped automatically after running pytest command on github action when using nest_asyncio.apply() in fastapi

# main.py from fastapi import FastAPI import nest_asyncio nest_asyncio.apply() app = FastAPI() @app.get('/hello') def hello(): return {'msg': 'hello'} # test_main.py from .main import app client = TestClient(app) def test_hello(): res…
Angie
  • 21
  • 1
2
votes
1 answer

Writing pytest testcases for asyncio with streams

I am trying to write a pytest testcase for a asyncio function which does read the output streams (stderr/stdout) and modifies the lines. The function I want to test (which again gets called inside asyncio.gather) is as shown below: import…
SKP
  • 33
  • 6
1
vote
1 answer

Python script using `asyncio` library won't stop running

I am using the libraries telethon and asyncio to scrape messages on Telegram but somehow my Python script below won't stop running. It got to the stage where it's printing out all the filtered messages correctly (under code line print(message.date,…
Leockl
  • 1,906
  • 5
  • 18
  • 51
1
vote
1 answer

PyTest Stuck When Upgrading From Python 3.8.3 to 3.10.7

I am developing an API in Python using FastAPI. I followed the user guide on https://fastapi.tiangolo.com/ and am very satisfied with the application. I wanted to upgrade the Python version from 3.8.3 to 3.10.7 but I experienced a strange behavior…
silenum
  • 149
  • 1
  • 2
  • 11
1
vote
1 answer

"RuntimeError: Cannot enter into task while another task is being executed" only showing up after first API call with FastAPI

I am using FastAPI, and strangely, only on the first API call I get the error "RuntimeError: Cannot enter into task while another task is being executed." I have supplied some sample code that should reproduce this error. import asyncio import…
1
vote
1 answer

does nest-asyncio runs coroutins on separate thread?

We're using tornadoweb which already runs an event loop single-threaded, and we want to use asyncio.run to run other coroutines, but it show error 'Event loop already running', found this library nest-asyncio that allows event loop to be nested,…
1
vote
1 answer

Kernel freezes when running federated computation with tensorflow_federated and nest_asyncio

I try to run a simple federated computation using tensorflow_federated. tff.federated_computation() -> after running this, the kernel freezes and am not able to run other cells. TF-Federated needs asyncio to prevent this error. My code is available…
0
votes
1 answer

'aiohttp' library taking the same amount of time completing multiple request as regular 'requests' library

I have 227 links where I am trying to fetch the html. I am using Python and jupyter notebook. I noticed that my asynchronous requests using 'aiohttp' and 'asyncio' library was taking the same time as when using normal "requests" library which i…
MARUF
  • 1
  • 1
0
votes
1 answer

Run Websocket in a separate Thread, updating class attributes

I want to implement a class with the possibility to start various websockets in different threads to retrieve market data and update the class attributes. I am using the kucoin-python-sdk library to that purpose. The below works fine in spyder,…
user2518293
  • 43
  • 1
  • 4
0
votes
3 answers

Not seeing speed up with Python Async IO

I have an IO operation (POST request for each Pandas row) which I'm trying to speed up using Async IO. An alternative minimal example can be found below. I want to understand why the 1st sample doesn't run in parallel and 2nd sample is faster. 1st…
Nishanth
  • 6,932
  • 5
  • 26
  • 38
0
votes
0 answers

Why does an awaited python coroutine not run (or finish?)?

In this minimum reproducible example, every minute at :00 I'm expecting to see the output of future stuff, but I don't. Instead, all I get every :00 is: # python3 test2.py firing.. stuff firing.. stuff
Jason
  • 404
  • 4
  • 14
0
votes
1 answer

Easy way python async method wanted

I am developing a small media player app on raspberry pi. So This have two main functions. Namely radio and file player. If entered into file player below is the code : process = subprocess.Popen(['omxplayer',songs[0],'-o','local'],…
Bineesh Kumar
  • 123
  • 10
0
votes
1 answer

Async/await of asyncio with nest_asyncio package is always returning coroutine 'get1' was never awaited

Hii guys I am using asyncio with nest_asyncio but I am always getting coroutine never awaited import asyncio import tracemalloc import aiohttp import nest_asyncio import json tracemalloc.start() async def request_call(url): async with…
vibhor Gupta
  • 103
  • 11
1
2