fluentpython / asyncio-tkinter Goto Github PK
View Code? Open in Web Editor NEWExample of running asyncio on top of the Tcl/Tk event loop via Tkinter
Example of running asyncio on top of the Tcl/Tk event loop via Tkinter
use https://docs.python.org/3/library/tkinter.html#tkinter.Widget.tk.createfilehandler and not an asyncio eventloop in a thread
In either tkapp.py or tkapp2.py, clicking the "Count Words" or "Call with futures" button respectively (both of which use futures) gives the following error in Python 3.5:
exception calling callback for <Future at 0x10e9242b0 state=finished returned list>
Traceback (most recent call last):
File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/concurrent/futures/_base.py", line 297, in _invoke_callbacks
callback(self)
File ".../asyncio-tkinter/guievents.py", line 43, in <lambda>
self.call_soon_threadsafe(new_future._copy_state, future))
AttributeError: 'Future' object has no attribute '_copy_state'
Hallo,
I just started this project: https://github.com/duk3luk3/faflauncher
Where I'm trying to use asyncio-tkinter and also aiohttp.
With the code as it is in the repo currently:
import tkinter as tk
from tkevents import TkEventLoop
import asyncio
import updater
class Application(tk.Frame):
def __init__(self, master=None):
super().__init__(master)
self.pack()
self.create_widgets()
#asyncio.async(self.launch())
#self.do_github()
#asyncio.get_event_loop().run_until_complete(self.do_github())
...
def launch(self, loop):
f = asyncio.ensure_future(updater.fetch_tags('FAForever', 'client'), loop=loop)
f.add_done_callback(app.set_github)
def set_github(self, fut):
tag, zipball_url = fut.result()
self.label["text"] = "{} => {}".format(tag, zipball_url)
root = tk.Tk()
app = Application(master=root)
#app.mainloop()
loop = TkEventLoop(app)
app.launch(loop)
loop.mainloop()
I get this error:
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib64/python3.6/tkinter/__init__.py", line 1699, in __call__
return self.func(*args)
File "/usr/lib64/python3.6/tkinter/__init__.py", line 745, in callit
func(*args)
File "src/tkevents.py", line 46, in <lambda>
lambda cb, a : cb(*a),
File "src/__main__.py", line 44, in set_github
tag, zipball_url = fut.result()
File "src/updater.py", line 20, in fetch_tags
response = await fetch(session, url)
File "src/updater.py", line 13, in fetch
async with session.get(url) as response:
File "/home/erlacher/git/faf/launcher/.venv/lib/python3.6/site-packages/aiohttp/client.py", line 603, in __aenter__
self._resp = yield from self._coro
File "/home/erlacher/git/faf/launcher/.venv/lib/python3.6/site-packages/aiohttp/client.py", line 231, in _request
conn = yield from self._connector.connect(req)
File "/home/erlacher/git/faf/launcher/.venv/lib/python3.6/site-packages/aiohttp/connector.py", line 378, in connect
proto = yield from self._create_connection(req)
File "/home/erlacher/git/faf/launcher/.venv/lib/python3.6/site-packages/aiohttp/connector.py", line 687, in _create_connection
_, proto = yield from self._create_direct_connection(req)
File "/home/erlacher/git/faf/launcher/.venv/lib/python3.6/site-packages/aiohttp/connector.py", line 698, in _create_direct_connection
hosts = yield from self._resolve_host(req.url.raw_host, req.port)
File "/home/erlacher/git/faf/launcher/.venv/lib/python3.6/site-packages/aiohttp/connector.py", line 669, in _resolve_host
self._resolver.resolve(host, port, family=self._family)
File "/home/erlacher/git/faf/launcher/.venv/lib/python3.6/site-packages/aiohttp/resolver.py", line 31, in resolve
host, port, type=socket.SOCK_STREAM, family=family)
RuntimeError: Task <Task pending coro=<fetch_tags() running at src/updater.py:20> cb=[Application.set_github()]> got Future <Future pending cb=[_chain_future.<locals>._call_check_cancel() at /usr/lib64/python3.6/asyncio/futures.py:408]> attached to a different loop
This seems to be a somewhat common problem when trying to merge two async projects.
Can you give me any insights into why that is and how to fix it?
Which file is the one to start with? I tried to start tkapp.py or tkapp2.py.
In both cases I get:
d:\daten\python\asyncio-tkinter-master>python3 tkapp2.py
File "tkapp2.py", line 11
def async(it, *args):
^
SyntaxError: invalid syntax
I am using python 3.7.0 on Windows 10.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.