jupyter / jupyter_console

Jupyter Terminal Console
http://jupyter-console.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
250 stars 145 forks source link

real time live output from background ioloop #210

Open ppkwiatkowski opened 4 years ago

ppkwiatkowski commented 4 years ago

Is it possible to show output from background ioloop process in real time and not only when prompting for it? It is a problem when using applications that are logging something.

minimal repro:

  1. Run import tornado; tornado.ioloop.PeriodicCallback(lambda: print("test output"), 2000).start() in jupyter-console.
  2. When I hit enter I get "test output" lines but they dont show up live.
ppkwiatkowski commented 4 years ago

Btw. with async prompt-toolkit version >= 3.0.3 it was fairly easy to implement for my use-case by overwriting mainloop from ZMQTerminalInteractiveShell in my inherited shell class like that:

    async def handle_background_iopub(self):
        while self.keep_running:
            self.handle_iopub()
            await asyncio.sleep(1)

    def mainloop(self):
        asyncio.ensure_future(self.handle_background_iopub())
        super().mainloop()

but maybe it could be done better