Re: asyncio questions

2023-01-27 Thread Frank Millman
On 2023-01-27 2:14 PM, Frank Millman wrote: I have changed it to async, which I call with 'asyncio.run'. It now looks like this -     server = await asyncio.start_server(handle_client, host, port)     await setup_companies()     session_check = asyncio.create_task(     check_sessions(

Re: asyncio questions

2023-01-27 Thread Frank Millman
On 2023-01-26 7:16 PM, Dieter Maurer wrote: Frank Millman wrote at 2023-1-26 12:12 +0200: I have written a simple HTTP server using asyncio. It works, but I don't always understand how it works, so I was pleased that Python 3.11 introduced some new high-level concepts that hide the gory details.

Re: asyncio questions

2023-01-26 Thread Dieter Maurer
Frank Millman wrote at 2023-1-26 12:12 +0200: >I have written a simple HTTP server using asyncio. It works, but I don't >always understand how it works, so I was pleased that Python 3.11 >introduced some new high-level concepts that hide the gory details. I >want to refactor my code to use these co

Re: asyncio questions

2023-01-26 Thread Grant Edwards
On 2023-01-26, Frank Millman wrote: > I have written a simple HTTP server using asyncio. It works, but I don't > always understand how it works, I thought that was the rule with asyncio. ;) -- https://mail.python.org/mailman/listinfo/python-list

Re: asyncio and tkinter (was: What should go to stdout/stderr and why Python logging write everything to stderr?)

2023-01-05 Thread Thomas Passin
On 1/5/2023 7:52 PM, Stefan Ram wrote: Thomas Passin writes: On 1/5/2023 4:24 PM, Stefan Ram wrote: You often can replace threads in tkinter by coroutines using asyncio when you write a replacement for the mainloop of tkinter that uses asyncio. Now, try to read only the official documentation

Re: asyncio+tkinter

2022-03-31 Thread Skip Montanaro
> > > Given that both asyncio & tkinter are modules in the standard lib and > both > > have event loops, I would have expected to find some "best practice" > > solution to mixing the two. > > Agreed. For GTK, you can use a dedicated loop policy like this: > > import asyncio_glib > asyncio.set_event

Re: asyncio+tkinter

2022-03-21 Thread Chris Angelico
On Tue, 22 Mar 2022 at 10:52, Skip Montanaro wrote: > > Given that both asyncio & tkinter are modules in the standard lib and both > have event loops, I would have expected to find some "best practice" > solution to mixing the two. I've not used asyncio, but might find it useful > with the pynput

Re: asyncio question

2020-11-03 Thread Kyle Stanley
On Tue, Nov 3, 2020 at 3:27 AM Frank Millman wrote: > It works, and it does look neater. But I want to start some background > tasks before starting the server, and cancel them on Ctrl+C. > > Using the 'old' method, I can wrap 'loop.run_forever()' in a > try/except/finally, check for KeyboardInt

Re: Asyncio Queue implementation suggestion

2020-09-18 Thread Barry Scott
> On 17 Sep 2020, at 15:51, Dennis Lee Bieber wrote: > > On Wed, 16 Sep 2020 13:39:51 -0400, Alberto Sentieri <2...@tripolho.com> > declaimed the following: > > >> devices tested simultaneously, I soon run out of file descriptor. Well, >> I increased the number of file descriptor in the appl

Re: Asyncio Queue implementation suggestion

2020-09-17 Thread Léo El Amri via Python-list
On 17/09/2020 16:51, Dennis Lee Bieber wrote: > On Wed, 16 Sep 2020 13:39:51 -0400, Alberto Sentieri <2...@tripolho.com> > declaimed the following: > >> devices tested simultaneously, I soon run out of file descriptor. Well, >> I increased the number of file descriptor in the application and then

Re: Asyncio Queue implementation suggestion

2020-09-17 Thread Léo El Amri via Python-list
Hello Alberto, I scrambled your original message a bit here. > Apparently asyncio Queues use a Linux pipe and each queue require 2 file > descriptors. Am I correct? As far as I know (And I know a bit about asyncio in CPython 3.5+) asyncio.queues.Queue doesn't use any file descriptor. It is imple

Re: Asyncio question (rmlibre)

2020-02-28 Thread Frank Millman
On 2020-02-28 1:37 AM, rmli...@riseup.net wrote: > What resources are you trying to conserve? > > If you want to try conserving time, you shouldn't have to worry about > starting too many background tasks. That's because asyncio code was > designed to be extremely time efficient at handling larg

Re: Asyncio question (rmlibre)

2020-02-27 Thread rmlibre
What resources are you trying to conserve? If you want to try conserving time, you shouldn't have to worry about starting too many background tasks. That's because asyncio code was designed to be extremely time efficient at handling large numbers of concurrent async tasks. For your application

Re: Asyncio question

2020-02-21 Thread Frank Millman
On 2020-02-21 11:13 PM, Greg Ewing wrote: On 21/02/20 7:59 pm, Frank Millman wrote: My first attempt was to create a background task for each session which runs for the life-time of the session, and 'awaits' its queue. It works, but I was concerned about having a lot a background tasks active

Re: Asyncio question

2020-02-21 Thread Greg Ewing
On 21/02/20 7:59 pm, Frank Millman wrote: My first attempt was to create a background task for each session which runs for the life-time of the session, and 'awaits' its queue. It works, but I was concerned about having a lot a background tasks active at the same time. The whole point of asyn

Re: asyncio based xdserver (libdurus 4.1)

2019-04-13 Thread Soppy bear
References: 1. https://bitbucket.org/tkadm30/libschevo/src/4.0-devel/lib/schevo/xdserver/server.py 2. https://bitbucket.org/tkadm30/libschevo/src/4.0-devel/tools/schevo-daemonize Sorry i might have talked too fast... lol :) i am still not sure yet how python 3 internally use asyncio with linu

RE: asyncio Question

2019-03-15 Thread Joseph L. Casale
> -Original Message- > From: Python-list bounces+jcasale=activenetwerx@python.org> On Behalf Of Simon > Connah > Sent: Thursday, March 14, 2019 3:03 AM > To: Python > Subject: asyncio Question > > Hi, > > Hopefully this isn't a stupid question. For the record I am using Python > 3.7

Re: Asyncio tasks getting cancelled

2018-11-21 Thread ike
Sorry for the latency. On Tue, Nov 06, 2018 at 03:39:24PM -0700, Ian Kelly wrote: > > What I meant was, the error message is specific to futures in the > > 'PENDING' state. Which should be set to 'RUNNING' before any actions > > occur. So it appears the tasks weren't started at all. > > Ah. I don

Re: Asyncio tasks getting cancelled

2018-11-06 Thread Ian Kelly
On Tue, Nov 6, 2018 at 3:39 PM Ian Kelly wrote: > > n Mon, Nov 5, 2018 at 8:43 PM wrote: > > What I meant was, the error message is specific to futures in the > > 'PENDING' state. Which should be set to 'RUNNING' before any actions > > occur. So it appears the tasks weren't started at all. > > Ah

Re: Asyncio tasks getting cancelled

2018-11-06 Thread Ian Kelly
n Mon, Nov 5, 2018 at 8:43 PM wrote: > > On Mon, Nov 05, 2018 at 07:15:04PM -0700, Ian Kelly wrote: > > > For context: > > > https://github.com/ldo/dbussy/issues/13 > > > https://gist.github.com/tu500/3232fe03bd1d85b1529c558f920b8e43 > > > > > > It really feels like asyncio is loosing strong refer

Re: Asyncio tasks getting cancelled

2018-11-05 Thread ike
On Mon, Nov 05, 2018 at 07:15:04PM -0700, Ian Kelly wrote: > > For context: > > https://github.com/ldo/dbussy/issues/13 > > https://gist.github.com/tu500/3232fe03bd1d85b1529c558f920b8e43 > > > > It really feels like asyncio is loosing strong references to scheduled > > tasks, as excplicitly keeping

Re: Asyncio tasks getting cancelled

2018-11-05 Thread Ian Kelly
On Mon, Nov 5, 2018 at 6:20 PM wrote: > Again sorry for the confusion, but I don't think this is an issue with > restarting loops, as this isn't happening in my application. Sure, I wasn't talking about restarting loops so much as strategies for making sure that everything has completed in the fi

Re: Asyncio tasks getting cancelled

2018-11-05 Thread philip . m
On Mon, Nov 05, 2018 at 01:57:56PM -0700, Ian Kelly wrote: > > Which is what I want in this case. Scheduling a new (long-running) task > > as a side effect, but returning early oneself. The new task can't be > > awaited right there, because the creating one should return already. > > If you want t

Re: Asyncio tasks getting cancelled

2018-11-05 Thread ike
On Tue, Nov 06, 2018 at 12:45:03AM +0100, i...@koeln.ccc.de wrote: > Also, I may be overlooking things, but I haven't found a way to add a > task before calling run_forever(), as asyncio will then say the loop > isn't running yet. So I'm not sure how you would jumpstart in that case. Ok, I was con

Re: Asyncio tasks getting cancelled

2018-11-05 Thread ike
On Mon, Nov 05, 2018 at 01:57:56PM -0700, Ian Kelly wrote: > > Which is what I want in this case. Scheduling a new (long-running) task > > as a side effect, but returning early oneself. The new task can't be > > awaited right there, because the creating one should return already. > > If you want t

Re: Asyncio tasks getting cancelled

2018-11-05 Thread Ian Kelly
On Mon, Nov 5, 2018 at 8:41 AM wrote: > > > But anyway, I highly recommend you to use the "await other_coroutine()" > > > syntax I talked about earlier. It may even fix the issue (90% chance). > > > > This should indeed fix the issue, but this is definitely not what one is > > looking for if one r

Re: Asyncio tasks getting cancelled

2018-11-05 Thread Léo El Amri via Python-list
On 05/11/2018 16:38, i...@koeln.ccc.de wrote: > I just saw, actually > using the same loop gets rid of the behavior in this case and now I'm > not sure about my assertions any more. It's fixing the issue because you're running loop with the run_forever(). As Ian and myself pointed out, using both

Re: Asyncio tasks getting cancelled

2018-11-05 Thread ike
This weird mixing was actually a side effect of me quickly coming up with a small example, sorry for the confusion. I just saw, actually using the same loop gets rid of the behavior in this case and now I'm not sure about my assertions any more. Yet it still looks like asyncio doen'st keep strong r

Re: Asyncio tasks getting cancelled

2018-11-05 Thread Léo El Amri via Python-list
On 05/11/2018 07:55, Ian Kelly wrote: >> I assume it's kind of a run_forever() with some code before it >> to schedule the coroutine. > > My understanding of asyncio.run() from > https://github.com/python/asyncio/pull/465 is that asyncio.run() is > more or less the equivalent of loop.run_until_com

Re: Asyncio tasks getting cancelled

2018-11-04 Thread Ian Kelly
On Sun, Nov 4, 2018 at 3:58 PM Léo El Amri via Python-list wrote: > > On 04/11/2018 20:25, i...@koeln.ccc.de wrote: > > I'm having trouble with asyncio. Apparently tasks (asyncio.create_task) > > are not kept referenced by asyncio itself, causing the task to be > > cancelled when the creating func

Re: Asyncio tasks getting cancelled

2018-11-04 Thread Léo El Amri via Python-list
On 04/11/2018 20:25, i...@koeln.ccc.de wrote: > I'm having trouble with asyncio. Apparently tasks (asyncio.create_task) > are not kept referenced by asyncio itself, causing the task to be > cancelled when the creating function finishes (and noone is awaiting the > corresponding futue). Am I doing s

Re: asyncio await different coroutines on the same socket?

2018-10-05 Thread Russell Owen
On Oct 3, 2018, Ian Kelly wrote (in article): > On Wed, Oct 3, 2018 at 7:47 AM Russell Owen wrote: > > Using asyncio I am looking for a simple way to await multiple events where > > notification comes over the same socket (or other serial stream) in > > arbitrary > > order. For example, suppose

Re: asyncio await different coroutines on the same socket?

2018-10-03 Thread Ian Kelly
On Wed, Oct 3, 2018 at 7:47 AM Russell Owen wrote: > Using asyncio I am looking for a simple way to await multiple events where > notification comes over the same socket (or other serial stream) in arbitrary > order. For example, suppose I am communicating with a remote device that can > run diffe

Re: asyncio await different coroutines on the same socket?

2018-10-03 Thread Léo El Amri via Python-list
Hello Russell, On 03/10/2018 15:44, Russell Owen wrote: > Using asyncio I am looking for a simple way to await multiple events where > notification comes over the same socket (or other serial stream) in arbitrary > order. For example, suppose I am communicating with a remote device that can > r

Re: asyncio: Warning message when waiting for an Event set by AbstractLoop.add_reader

2018-08-12 Thread Léo El Amri via Python-list
I found out what was the problem. The behavior of my "reader" (The callback passed to AbstractEventLoop.add_reader()) is to set an event. This event is awaited for in a coroutine which actually reads what is written on a pipe. The execution flow is the following: * NEW LOOP TURN * The selector aw

Re: asyncio: Warning message when waiting for an Event set by AbstractLoop.add_reader

2018-08-03 Thread Léo El Amri via Python-list
Thanks for the answer, but the problem is that this is happening in the built-in Event of the asyncio package; which is actually a coroutine. I don't expect the built-in to have this kind of behavior. I guess I'll have to dig on the source code of the asyncio default loop to actually understand how

Re: asyncio: Warning message when waiting for an Event set by AbstractLoop.add_reader

2018-08-02 Thread dieter
Léo El Amri via Python-list writes: > ... > WARNING:asyncio:Executing took 1.000 seconds > ... > But there is still this warning... At your place, I would look at the code responsible for the warning. I assume that it is produced because the waiting time is rather high -- but this is just a gue

Re: asyncio awaitable object

2017-12-08 Thread Ian Kelly
On Fri, Dec 8, 2017 at 2:08 AM, ast wrote: > Hello, > > According to: https://www.python.org/dev/peps/pep-0492/#await-expression > an awaitable object is: > > - A native coroutine object returned from a native coroutine function > - A generator-based coroutine object returned from a function decor

Re: asyncio awaitable object

2017-12-08 Thread ast
"ast" a écrit dans le message de news:5a2a568c$0$3699$426a7...@news.free.fr... I made some experiment. It seems that the iterator shall provide None values, an other value raises an exception: "RuntimeError: Task got bad yield: 1" and in instruction "res = await obj", res got the StopIterati

Re: asyncio loop.call_soon()

2017-11-28 Thread Terry Reedy
On 11/28/2017 11:02 AM, Ian Kelly wrote: On Tue, Nov 28, 2017 at 8:30 AM, ast wrote: Hello Python's doc says about loop.call_soon(callback, *arg): Arrange for a callback to be called as soon as possible. The callback is called after call_soon() returns, when control returns to the event loop.

Re: asyncio loop.call_soon()

2017-11-28 Thread Ian Kelly
On Tue, Nov 28, 2017 at 8:30 AM, ast wrote: > Hello > > Python's doc says about loop.call_soon(callback, *arg): > > Arrange for a callback to be called as soon as possible. The callback is > called after call_soon() returns, when control returns to the event loop. > > But it doesn't seem to be tru

Re: asyncio Behaviour Difference 3.6 vs 3.5 (Posting On Python-List Prohibited)

2017-06-11 Thread llanitedave
On Sunday, June 11, 2017 at 2:42:41 AM UTC-7, Lawrence D’Oliveiro wrote: > I tried the following very simple script under both versions 3.5.3 and 3.6.1 > of Python: > > import sys > import asyncio > > loop = asyncio.get_event_loop() > > async def idle() : > while True :

Re: asyncio does not always show the full traceback

2017-03-03 Thread gst
Le mercredi 1 mars 2017 09:25:48 UTC-5, Frank Millman a écrit : > "Frank Millman" wrote in message news:o93vs2$smi$1...@blaine.gmane.org... SNIP > > If you run this as is, it works. > > I added '1/0' at various points, to force an exception. > > If I put it in main() or in aenum(), I do not

Re: asyncio does not always show the full traceback

2017-03-02 Thread Frank Millman
"INADA Naoki" wrote in message news:caefz+tz8hvwmh5cf17mv3accdqthj1axddga8umnznuuwes...@mail.gmail.com... > For completeness, if I place '1/0' in aenum(), I get exactly the same > traceback as the first one above. > I can't reproduce it too. Did you 3.6.0 this time? Or did you used 3.6b4 aga

Re: asyncio does not always show the full traceback

2017-03-02 Thread INADA Naoki
FYI, you can easily find this changelog of Python 3.6rc1: - bpo-28843: Fix asyncio C Task to handle exceptions __traceback__. See also: https://bugs.python.org/issue28843 On Fri, Mar 3, 2017 at 1:11 AM, INADA Naoki wrote: >> For completeness, if I place '1/0' in aenum(), I get exactly the same

Re: asyncio does not always show the full traceback

2017-03-02 Thread INADA Naoki
> For completeness, if I place '1/0' in aenum(), I get exactly the same > traceback as the first one above. > I can't reproduce it too. Did you 3.6.0 this time? Or did you used 3.6b4 again? Please don't use beta when asking question or reporting bug. -- https://mail.python.org/mailman/listinfo/p

Re: asyncio does not always show the full traceback

2017-03-02 Thread Frank Millman
"Frank Millman" wrote in message news:o994og$84k$1...@blaine.gmane.org... If I place '1/0' in main(), this is the traceback - Traceback (most recent call last): File "test_db1a.py", line 25, in loop.run_until_complete(main()) File "/usr/local/lib/python3.6/asyncio/base_events.py", lin

Re: asyncio does not always show the full traceback

2017-03-02 Thread Chris Angelico
On Thu, Mar 2, 2017 at 11:55 PM, Frank Millman wrote: > If I place '1/0' in main(), this is the traceback - > > Traceback (most recent call last): > File "test_db1a.py", line 25, in >loop.run_until_complete(main()) > File "/usr/local/lib/python3.6/asyncio/base_events.py", line 466, in > run

Re: asyncio does not always show the full traceback

2017-03-02 Thread INADA Naoki
Could you use 3.6.0 instead of b4? I added 1/0 at: ... async def main(): 1/0 await aenum() ... then: $ pyenv/versions/3.6.0/bin/python3 -VV Python 3.6.0 (default, Jan 16 2017, 19:41:10) [GCC 6.2.0 20161005] $ pyenv/versions/3.6.0/bin/python3 a.py Traceback (most recent call last): File

Re: asyncio does not always show the full traceback

2017-03-02 Thread Frank Millman
"INADA Naoki" wrote in message news:caefz+tyudwjesyttqzg2_romphmjrxqaga2ulgfqv5qbpii...@mail.gmail.com... I can't reproduce it on Linux. Maybe, it's windows specific bug? import asyncio from itertools import count async def aenumerate(aiterable): counter = count() async for x in aite

Re: asyncio does not always show the full traceback

2017-03-02 Thread INADA Naoki
I can't reproduce it on Linux. Maybe, it's windows specific bug? On Wed, Mar 1, 2017 at 11:25 PM, Frank Millman wrote: > "Frank Millman" wrote in message news:o93vs2$smi$1...@blaine.gmane.org... >> >> >> I use asyncio in my project, so most of my functions start with 'async' >> and > > most of m

Re: asyncio does not always show the full traceback

2017-03-01 Thread Frank Millman
"Frank Millman" wrote in message news:o93vs2$smi$1...@blaine.gmane.org... I use asyncio in my project, so most of my functions start with 'async' and most of my calls are preceded by 'await'. If an exception is raised, I usually get the full traceback, but sometimes I just get something l

Re: asyncio does not always show the full traceback

2017-02-28 Thread dieter
"Frank Millman" writes: > I use asyncio in my project, so most of my functions start with > 'async' and most of my calls are preceded by 'await'. > > If an exception is raised, I usually get the full traceback, but > sometimes I just get something like the following - > > Traceback (most recent ca

Re: asyncio does not always show the full traceback

2017-02-28 Thread Frank Millman
John Ladasky wrote in message news:72209011-db09-4ba2-9c5b-f576a30e2...@googlegroups.com... > Does anyone know what I must change to get the full traceback? Three years ago, I had a similar issue with incomplete tracebacks while using multiprocessing.Pool. The discussion is here: https://g

Re: asyncio does not always show the full traceback

2017-02-28 Thread jladasky
> Does anyone know what I must change to get the full traceback? Three years ago, I had a similar issue with incomplete tracebacks while using multiprocessing.Pool. The discussion is here: https://groups.google.com/forum/#!msg/comp.lang.python/qKTNNt8uKKU/biNyslh19ncJ;context-place=msg/comp.la

Re: asyncio question

2016-12-13 Thread Frank Millman
"Ian Kelly" wrote in message news:CALwzid=vdczAH18mHKaL7ryvDUB=7_y-JVUrTkRZ=gkz66p...@mail.gmail.com... On Tue, Dec 13, 2016 at 6:15 AM, Frank Millman wrote: > The client uses AJAX to send messages to the server. It sends the > message > and continues processing, while a background task waits

Re: asyncio question

2016-12-13 Thread Ian Kelly
On Tue, Dec 13, 2016 at 6:15 AM, Frank Millman wrote: > The client uses AJAX to send messages to the server. It sends the message > and continues processing, while a background task waits for the response and > handles it appropriately. As a result, the client can send a second message > before re

Re: Asyncio -- delayed calculation

2016-12-02 Thread Chris Angelico
On Sat, Dec 3, 2016 at 1:26 AM, Frank Millman wrote: > Then Twisted made a strong case for an asynchronous approach. One of their > claims (which I have no reason to doubt) was that, because each user > 'session' spends most of its time waiting for something - keyboard input, > reply from database

Re: Asyncio -- delayed calculation

2016-12-02 Thread Marko Rauhamaa
"Frank Millman" : > Then Twisted made a strong case for an asynchronous approach. One of > their claims (which I have no reason to doubt) was that, because each > user 'session' spends most of its time waiting for something - > keyboard input, reply from database, etc - their approach allows > hund

Re: Asyncio -- delayed calculation

2016-12-02 Thread Frank Millman
"Steve D'Aprano" wrote in message news:58417e2d$0$1612$c3e8da3$54964...@news.astraweb.com... My first impressions on this is that we have a couple of good models for preemptive parallelism, threads and processes, both of which can do everything that concurrency can do, and more, and both of whi

Re: Asyncio -- delayed calculation

2016-12-02 Thread Marko Rauhamaa
Steve D'Aprano : > py> await x > File "", line 1 > await x > ^ > SyntaxError: invalid syntax "await" is only allowed inside a coroutine. > So why do we need asyncio? What is it actually good for? Asyncio is a form of cooperative multitasking. It presents a framework of "fake thr

Re: Asyncio -- delayed calculation

2016-12-02 Thread Steve D'Aprano
On Thu, 1 Dec 2016 06:53 pm, Christian Gollwitzer wrote: > well that works - but I think it it is possible to explain it, without > actually understanding what it does behind the scences: > > x = foo() > # schedule foo for execution, i.e. put it on a TODO list > > await x > # run the TODO list u

Re: Asyncio -- delayed calculation

2016-12-01 Thread Ian Kelly
On Thu, Dec 1, 2016 at 12:53 AM, Christian Gollwitzer wrote: > well that works - but I think it it is possible to explain it, without > actually understanding what it does behind the scences: > > x = foo() > # schedule foo for execution, i.e. put it on a TODO list This implies that if you never a

Re: Asyncio -- delayed calculation

2016-11-30 Thread Christian Gollwitzer
Am 30.11.16 um 22:07 schrieb Gregory Ewing: Chris Angelico wrote: That's because you're not actually running anything concurrently. Yes, I know what happens and why. My point is that for someone who *doesn't* know, simplistic attempts to explain what "await" means can be very misleading. The

Re: Asyncio -- delayed calculation

2016-11-30 Thread Marko Rauhamaa
Gregory Ewing : > My point is that for someone who *doesn't* know, simplistic attempts > to explain what "await" means can be very misleading. > > There doesn't seem to be any accurate way of summarising it in a few > words. The best we can do seems to be to just say "it's a magic word > that you h

Re: Asyncio -- delayed calculation

2016-11-30 Thread Marko Rauhamaa
Terry Reedy : > On 11/30/2016 7:53 AM, Chris Angelico wrote: > >> I also think that everyone should spend some time writing >> multithreaded code before switching to asyncio. It'll give you a >> better appreciation for what's going on. > > I so disagree with this. I have written almost no thread c

Re: Asyncio -- delayed calculation

2016-11-30 Thread Gregory Ewing
Chris Angelico wrote: That's because you're not actually running anything concurrently. Yes, I know what happens and why. My point is that for someone who *doesn't* know, simplistic attempts to explain what "await" means can be very misleading. There doesn't seem to be any accurate way of sum

Re: Asyncio -- delayed calculation

2016-11-30 Thread Chris Kaynor
On Wed, Nov 30, 2016 at 10:58 AM, Chris Angelico wrote: > On Thu, Dec 1, 2016 at 5:54 AM, Terry Reedy wrote: >> On 11/30/2016 7:53 AM, Chris Angelico wrote: >> >>> I also think that everyone should spend some time writing >>> multithreaded code before switching to asyncio. It'll give you a >>> be

Re: Asyncio -- delayed calculation

2016-11-30 Thread Chris Angelico
On Thu, Dec 1, 2016 at 5:54 AM, Terry Reedy wrote: > On 11/30/2016 7:53 AM, Chris Angelico wrote: > >> I also think that everyone should spend some time writing >> multithreaded code before switching to asyncio. It'll give you a >> better appreciation for what's going on. > > > I so disagree with

Re: Asyncio -- delayed calculation

2016-11-30 Thread Terry Reedy
On 11/30/2016 7:53 AM, Chris Angelico wrote: I also think that everyone should spend some time writing multithreaded code before switching to asyncio. It'll give you a better appreciation for what's going on. I so disagree with this. I have written almost no thread code but have successfully

Re: Asyncio -- delayed calculation

2016-11-30 Thread Chris Angelico
On Wed, Nov 30, 2016 at 11:40 PM, Gregory Ewing wrote: > Chris Angelico wrote: >> >> From the point of view of >> the rest of Python, no. It's a sign saying "Okay, Python, you can >> alt-tab away from me now". > > > The problem with that statement is it implies that if > you omit the "await", then

Re: Asyncio -- delayed calculation

2016-11-30 Thread Gregory Ewing
Chris Angelico wrote: From the point of view of the rest of Python, no. It's a sign saying "Okay, Python, you can alt-tab away from me now". The problem with that statement is it implies that if you omit the "await", then the thing you're calling will run uninterruptibly. Whereas what actually

Re: Asyncio -- delayed calculation

2016-11-30 Thread Gregory Ewing
On Tuesday 29 November 2016 14:21, Chris Angelico wrote: "await" means "don't continue this function until that's done". It blocks the function until a non-blocking operation is done. That explanation gives the impression that it's some kind of "join" operation on parallel tasks, i.e. if you d

Re: Asyncio -- delayed calculation

2016-11-29 Thread Steve D'Aprano
On Wed, 30 Nov 2016 05:41 am, Ian Kelly wrote: > You mean how do you create something that can be awaited that doesn't > await something else in turn? With a Future. > > import asyncio > > class Awaitable(asyncio.Future): > def wake_up_later(self): > asyncio.get_event_loop().call_later(3,

Re: Asyncio -- delayed calculation

2016-11-29 Thread Ian Kelly
On Mon, Nov 28, 2016 at 10:42 PM, Chris Angelico wrote: > On Tue, Nov 29, 2016 at 4:13 PM, Paul Rubin wrote: >> >> I haven't gotten my head around Python asyncio and have been wanting >> to read this: >> >>http://lucumr.pocoo.org/2016/10/30/i-dont-understand-asyncio/ > > It's talking a lot ab

Re: Asyncio -- delayed calculation

2016-11-28 Thread Marko Rauhamaa
Gregory Ewing : > All the terminology around async/await is inherently confusing and > counterintuitive, IMO. I'm disappointed that we've ended up here. I think the conceptual mess can be clarified over time. Coroutines are essentially threads. Why Python needs two threading implementations is que

Re: Asyncio -- delayed calculation

2016-11-28 Thread Chris Angelico
On Tue, Nov 29, 2016 at 4:32 PM, Steven D'Aprano wrote: > On Tuesday 29 November 2016 14:21, Chris Angelico wrote: > >> On Tue, Nov 29, 2016 at 1:23 PM, Steve D'Aprano >> wrote: >>> This is confusing: why is this awaiting something inside an async function? >>> Doesn't that mean that the await as

Re: Asyncio -- delayed calculation

2016-11-28 Thread Chris Angelico
On Tue, Nov 29, 2016 at 4:13 PM, Paul Rubin wrote: > > I haven't gotten my head around Python asyncio and have been wanting > to read this: > >http://lucumr.pocoo.org/2016/10/30/i-dont-understand-asyncio/ It's talking a lot about how we got here, which isn't all necessary if you just want to

Re: Asyncio -- delayed calculation

2016-11-28 Thread Steven D'Aprano
On Tuesday 29 November 2016 14:21, Chris Angelico wrote: > On Tue, Nov 29, 2016 at 1:23 PM, Steve D'Aprano > wrote: >> This is confusing: why is this awaiting something inside an async function? >> Doesn't that mean that the await asyncio.gather(...) call is turned >> blocking? > > "await" means

Re: Asyncio -- delayed calculation

2016-11-28 Thread Paul Rubin
Chris Angelico writes: > Asynchronous I/O is something to get your head around I'd much > rather work with generator-based async functions... I haven't gotten my head around Python asyncio and have been wanting to read this: http://lucumr.pocoo.org/2016/10/30/i-dont-understand-asyncio/

Re: Asyncio -- delayed calculation

2016-11-28 Thread Nathan Ernst
To be fair, in other languages, such as C# or C++ with similar mechanisms, if you don't ask for the result from an async or future task, there's no guarantee the async task will be executed at all unless (or until) you ask for the result. C++'s futures even give an explicit flag indicating you want

Re: Asyncio -- delayed calculation

2016-11-28 Thread Chris Angelico
On Tue, Nov 29, 2016 at 3:16 PM, Gregory Ewing wrote: > Chris Angelico wrote: >> >> "await" means "don't continue this function until that's done". It >> blocks the function until a non-blocking operation is done. > > > However, *not* using 'await' doesn't mean the operation > will be done without

Re: Asyncio -- delayed calculation

2016-11-28 Thread Gregory Ewing
Chris Angelico wrote: "await" means "don't continue this function until that's done". It blocks the function until a non-blocking operation is done. However, *not* using 'await' doesn't mean the operation will be done without blocking. Rather, it won't be done at all (and is usually an error, b

Re: Asyncio -- delayed calculation

2016-11-28 Thread Zachary Ware
On Mon, Nov 28, 2016 at 6:48 AM, Steve D'Aprano wrote: > What am I doing wrong? Give yourself a bit more to debug with, since you're going to want to do something with the result your expensive calculation anyway: import asyncio class Counter: def __init__(self, i): self.count = 10

Re: Asyncio -- delayed calculation

2016-11-28 Thread Chris Angelico
On Tue, Nov 29, 2016 at 1:23 PM, Steve D'Aprano wrote: > This is confusing: why is this awaiting something inside an async function? > Doesn't that mean that the await asyncio.gather(...) call is turned > blocking? "await" means "don't continue this function until that's done". It blocks the func

Re: Asyncio -- delayed calculation

2016-11-28 Thread Zentrader
Take a look at Doug Hellmann's example using multiprocessing at https://pymotw.com/2/multiprocessing/basics.html You should be able to substitute the count down example directly into the first example. -- https://mail.python.org/mailman/listinfo/python-list

Re: Asyncio -- delayed calculation

2016-11-28 Thread Steve D'Aprano
On Tue, 29 Nov 2016 12:03 am, Chris Angelico wrote: > On Mon, Nov 28, 2016 at 11:48 PM, Steve D'Aprano > wrote: >> When I try running that, I get no output. No error, no exception, the >> run_until_complete simply returns instantly. > > When I do, I get this warning: > > asynctest.py:17: Runtim

Re: Asyncio -- delayed calculation

2016-11-28 Thread Chris Angelico
On Tue, Nov 29, 2016 at 11:20 AM, Steve D'Aprano wrote: > On Tue, 29 Nov 2016 02:53 am, Ian Kelly wrote: > >> In order for the coroutines to actually do anything, you need to >> schedule them in some way with the event loop. That could take the >> form of awaiting them from some other coroutine, o

Re: Asyncio -- delayed calculation

2016-11-28 Thread Steve D'Aprano
On Tue, 29 Nov 2016 02:53 am, Ian Kelly wrote: > In order for the coroutines to actually do anything, you need to > schedule them in some way with the event loop. That could take the > form of awaiting them from some other coroutine, or passing them > directly to loop.run_until_complete or event_l

Re: Asyncio -- delayed calculation

2016-11-28 Thread Ian Kelly
On Mon, Nov 28, 2016 at 5:48 AM, Steve D'Aprano wrote: > Let's pretend that the computation can be performed asynchronously, so that > I can have all five Counter objects counting down in parallel. I have this: > > > import asyncio > > class Counter: > def __init__(self): > self.count

Re: Asyncio -- delayed calculation

2016-11-28 Thread Chris Angelico
On Mon, Nov 28, 2016 at 11:48 PM, Steve D'Aprano wrote: > When I try running that, I get no output. No error, no exception, the > run_until_complete simply returns instantly. When I do, I get this warning: asynctest.py:17: RuntimeWarning: coroutine 'Counter.count_down' was never awaited obj.co

Re: asyncio and subprocesses

2016-04-24 Thread Terry Reedy
On 4/24/2016 6:07 PM, David wrote: Is this a bug in the asyncio libraries? Is this a fixed bug, already? I am using Python 3.4.2 as distributed in Ubuntu Lucid, with built-in asyncio. The people who patch asyncio do not read this list. Either install a current release or try the tulip rele

Re: asyncio - run coroutine in the background

2016-02-20 Thread Chris Angelico
On Sun, Feb 21, 2016 at 4:45 AM, Martin A. Brown wrote: > Another (non-Python) DNS name lookup library that does practically > the same thing (along with the shortcomingsn you mentioned, Chris: > no NSS nor /etc/hosts) is the adns library. Well, it is DNS, after > all. > > http://www.gnu.org/so

Re: asyncio - run coroutine in the background

2016-02-20 Thread Martin A. Brown
Hello there, I realize that this discussion of supporting asynchronous name lookup requests in DNS is merely a detour in this thread on asyncio, but I couldn't resist mentioning an existing tool. >> getaddrinfo is a notorious pain but I think it's just a library >> issue; an async version sho

Re: asyncio - run coroutine in the background

2016-02-20 Thread Kevin Conway
> getaddrinfo is a notorious pain but I think it's just a library issue; an async version should be possible in principle. How does Twisted handle it? Does it have a version? I think we're a little outside the scope of OP's question at this point, but for the sake of answering this: There are a

Re: asyncio - run coroutine in the background

2016-02-20 Thread Marko Rauhamaa
Paul Rubin : > I've just felt depressed whenever I've looked at any Python async > stuff. I've written many Python programs with threads and not gotten > into the trouble that people keep warning about. Programming-model-wise, asyncio is virtually identical with threads. In each, I dislike the im

Re: asyncio - run coroutine in the background

2016-02-20 Thread Chris Angelico
On Sat, Feb 20, 2016 at 7:59 PM, Marko Rauhamaa wrote: > Chris Angelico : > >> In a (non-Python) program of mine, I got annoyed by synchronous name >> lookups, so I hacked around it: instead of using the regular library >> functions, I just do a DNS lookup directly (which can then be >> event-base

Re: asyncio - run coroutine in the background

2016-02-20 Thread Marko Rauhamaa
Chris Angelico : > In a (non-Python) program of mine, I got annoyed by synchronous name > lookups, so I hacked around it: instead of using the regular library > functions, I just do a DNS lookup directly (which can then be > event-based - send a UDP packet, get notified when a UDP packet > arrives

Re: asyncio - run coroutine in the background

2016-02-20 Thread Chris Angelico
On Sat, Feb 20, 2016 at 7:37 PM, Paul Rubin wrote: > getaddrinfo is a notorious pain but I think it's just a library issue; > an async version should be possible in principle. How does Twisted > handle it? Does it have a version? In a (non-Python) program of mine, I got annoyed by synchronous n

Re: asyncio - run coroutine in the background

2016-02-20 Thread Paul Rubin
Marko Rauhamaa writes: > It would appear that disk I/O is considered nonblocking at a very deep > level: > * O_NONBLOCK doesn't have an effect > * a process waiting for the disk to respond cannot receive a signal > * a process waiting for the disk to respond stays in the "ready" state You can

  1   2   >