Message271324
[On #27579, Lodovic Gasc volunteered to open and help with an issue on the github asyncio-doc project.]
Ludovic, here is my current suggestion for the asyncio tutorial or how-to.
Adding a Tkinter GUI to an Asyncio Program
-------------------------------------------
Assume that the tkinter Tk instance is called 'root' and the asyncio loop is called 'loop'. Add a callback loop like the following.
def tk_update():
root.update()
loop.call_soon(tk_update) # or loop.call_later(delay, tk_update)
Call tk_update before each loop.run_forever() or loop.run_until_complete(...) call. Do not call root.mainloop() or root.quit(). Loop.stop() or completion of run_until_complete will stop the tk_update loop. This method is used in the following example.
---
Follow this with loop_tk2.py as an example. It is carefully written to be a template that people can build on. Some notes:
0. I REALLY like being able to write tkinter animations with async for.
1. I initially called loop.close immediately after loop.stop in App.close. This is a natural think for a tkinter programmer to do. But it does not work because loop.stop does not *immediately* take effect, and loop.close will typically get called before it does. Now I understand that loop.close() must physically follow loop.run_xxx() to ensure that it temporally follows the actual stopping of the loop.
2. I did not initially make a list of tasks. This worked once, but on the next run I got a "Task was destroyed but it is pending!:" message. Cancelling all 'forever' tasks makes for a clean shutdown.
If/when you open a thread, please post url here and I will subscribe.
[Guido, I will adapt this example for crawl.py.] |
|
Date |
User |
Action |
Args |
2016-07-26 05:41:16 | terry.reedy | set | recipients:
+ terry.reedy, gvanrossum, Ludovic.Gasc, serhiy.storchaka, yselivanov, Maxime S |
2016-07-26 05:41:16 | terry.reedy | set | messageid: <1469511676.49.0.5271682939.issue27546@psf.upfronthosting.co.za> |
2016-07-26 05:41:16 | terry.reedy | link | issue27546 messages |
2016-07-26 05:41:15 | terry.reedy | create | |
|