I think there may be some ambiguity in the wording. :-(

The intention is that you should call stop() from *inside* the loop, i.e.
when it is already running. It seems you interpreted the docs to mean that
stop() itself runs the remaining callbacks. That is not the case -- it
merely tells a running loop to stop.

How could we have made this clearer in the docs?


On Mon, Mar 31, 2014 at 4:55 PM, Lars Andersson <[email protected]> wrote:

> Hi,
>
> I'm a bit confused by the behaviour of loop.stop()
>
> The asyncio docs states that:
>
> "Every callback scheduled before 
> stop()<https://docs.python.org/dev/library/asyncio-eventloop.html#asyncio.BaseEventLoop.stop>
>  is
> called will run."
>
> Still, when running asyncio from python3.4 on OS X 10.9.2, the following
> program does not end up calling the callback() function:
>
> import asyncio
>
> def callback():
>     print("CALLBACK CALLED")
>
> loop = asyncio.get_event_loop()
> loop.call_soon(callback)
> #loop.run_until_complete(asyncio.sleep(0))
> loop.stop()
>
>
> Uncommenting the line calling asyncio.sleep(0) seems to fix the problem,
> and the callback is actually called. Is this expected behaviour?
>
>


-- 
--Guido van Rossum (python.org/~guido)

Reply via email to