Re: Using a background thread with asyncio/futures with flask

2024-03-24 Thread Frank Millman via Python-list
On 2024-03-23 3:25 PM, Frank Millman via Python-list wrote: It is not pretty! call_soon_threadsafe() is a loop function, but the loop is not accessible from a different thread. Therefore I include a reference to the loop in the message passed to in_queue, which in turn passes it to

Re: Using a background thread with asyncio/futures with flask

2024-03-23 Thread Frank Millman via Python-list
On 2024-03-22 12:08 PM, Thomas Nyberg via Python-list wrote: Hi, Yeah so flask does support async (when installed with `pip3 install flask[async]), but you are making a good point that flask in this case is a distraction. Here's an example using just the standard library that exhibits the

Re: Using a background thread with asyncio/futures with flask

2024-03-22 Thread Mark Bourne via Python-list
Thomas Nyberg wrote: Hi, Yeah so flask does support async (when installed with `pip3 install flask[async]), but you are making a good point that flask in this case is a distraction. Here's an example using just the standard library that exhibits the same issue: `app.py` ``` import asyncio

Re: Using a background thread with asyncio/futures with flask

2024-03-22 Thread Dieter Maurer via Python-list
dieter.mau...@online.de wrote at 2024-3-22 18:28 +0100: >Thomas Nyberg wrote at 2024-3-22 11:08 +0100: >> ... `future` use across thread boundaries ... >> Here's an example using just the standard library that >> exhibits the same issue: > ... >For use across thread boundaries, you likely will use

Re: Using a background thread with asyncio/futures with flask

2024-03-22 Thread Dieter Maurer via Python-list
Thomas Nyberg wrote at 2024-3-22 11:08 +0100: > ... `future` use across thread boundaries ... > Here's an example using just the standard library that > exhibits the same issue: I think all `asyncio` objects (futures, tasks, ...) are meant to be used in a single thread. If you use them across

Re: Using a background thread with asyncio/futures with flask

2024-03-22 Thread Frank Millman via Python-list
On 2024-03-22 1:23 PM, Frank Millman via Python-list wrote: On 2024-03-22 12:09 PM, Frank Millman via Python-list wrote: I am no expert. However, I do have something similar in my app, and it works. I do not use 'await future', I use 'asyncio.wait_for(future)'. I tested it and it did not

Re: Using a background thread with asyncio/futures with flask

2024-03-22 Thread Frank Millman via Python-list
On 2024-03-22 12:09 PM, Frank Millman via Python-list wrote: I am no expert. However, I do have something similar in my app, and it works. I do not use 'await future', I use 'asyncio.wait_for(future)'. I tested it and it did not work. I am not sure, but I think the problem is that you

Re: Using a background thread with asyncio/futures with flask

2024-03-22 Thread Lars Liedtke via Python-list
Sorry, must have missed that :-/ Lars Liedtke Lead Developer [Tel.] +49 721 98993- [Fax] +49 721 98993- [E-Mail]l...@solute.de solute GmbH Zeppelinstraße 15 76185 Karlsruhe Germany [Marken] Geschäftsführer | Managing Director: Dr. Thilo Gans, Bernd

Re: Using a background thread with asyncio/futures with flask

2024-03-22 Thread Frank Millman via Python-list
On 2024-03-20 10:22 AM, Thomas Nyberg via Python-list wrote: Hello, I have a simple (and not working) example of what I'm trying to do. This is a simplified version of what I'm trying to achieve (obviously the background workers and finalizer functions will do more later): `app.py` ```

Re: Using a background thread with asyncio/futures with flask

2024-03-22 Thread Thomas Nyberg via Python-list
Hi, Yeah so flask does support async (when installed with `pip3 install flask[async]), but you are making a good point that flask in this case is a distraction. Here's an example using just the standard library that exhibits the same issue: `app.py` ``` import asyncio import threading

Re: Using a background thread with asyncio/futures with flask

2024-03-22 Thread Chris Angelico via Python-list
On Fri, 22 Mar 2024 at 18:35, Lars Liedtke via Python-list wrote: > > Hey, > > As far as I know (might be old news) flask does not support asyncio. > > You would have to use a different framework, like e.g. FastAPI or similar. > Maybe someone has already written "flask with asyncio" but I don't

Re: Using a background thread with asyncio/futures with flask

2024-03-22 Thread Lars Liedtke via Python-list
Hey, As far as I know (might be old news) flask does not support asyncio. You would have to use a different framework, like e.g. FastAPI or similar. Maybe someone has already written "flask with asyncio" but I don't know about that. Cheers Lars Lars Liedtke Lead Developer [Tel.] +49 721

Using a background thread with asyncio/futures with flask

2024-03-20 Thread Thomas Nyberg via Python-list
Hello, I have a simple (and not working) example of what I'm trying to do. This is a simplified version of what I'm trying to achieve (obviously the background workers and finalizer functions will do more later): `app.py` ``` import asyncio import threading import time from queue import