Python 3.4 / GTK3 / Async



Hi

I use tkinter with a async function on a Linux/Window app.
Now I will use gtk3 instead of tkinter.
Is there also a way to run my async function?
How should I adapt the code
Here are some code fragments:

async def _event_loop(app, interval=0.05):
    try:
        while True:
            app.update()
            await asyncio.sleep(interval)
    except tkinter.TclError as exc:
        if "application has been destroyed" not in exc.args[0]:
            raise

class SSHFrame(tkinter.Frame):
    def __init__(self, parent):
        super().__init__(parent)
        ...
        ...
    async def _run(self, host, command, user, password):
        try:
            async with asyncssh.connect(host, username=user,
password=password,
                                        client_keys=None) as conn:
                self._proc = await conn.create_process(command,
                                                       term_type='dumb')
                while not self._proc.stdout.at_eof():
                    self._output(await self._proc.stdout.read(1024))

                self._output('\n[Disconnected]\n')
        except (asyncssh.Error, OSError) as exc:
            self._output('[%s]\n' % str(exc))
        finally:
            self._proc = None

class App(tkinter.Frame):
    def __init__(self, parent):
        super().__init__(parent)
        .....
        .....


asyncio.get_event_loop().run_until_complete(_event_loop(App(tkinter.Tk())))





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]