Run a tornado web server in a background thread:
from threading import Thread
from tornado import ioloop, web
class MyHandler(web.RequestHandler):
def get(self):
self.write("hi back")
def app_in_thread():
import asyncio
asyncio.set_event_loop(asyncio.new_event_loop())
app = web.Application(
[('/hello', MyHandler)]
)
app.listen(9999)
ioloop.IOLoop.current().start()
t = Thread(target=app_in_thread)
t.start()
You can now talk to server:
!curl http://localhost:9999/hello
hi back
Or link to it in output:
%%html
<a href="http://localhost:9999/hello" target="_blank">click here to say hi!</a>