#!/usr/bin/env python # coding: utf-8 # Run a tornado web server in a background thread: # In[1]: 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: # In[2]: get_ipython().system('curl http://localhost:9999/hello') # Or link to it in output: # In[4]: get_ipython().run_cell_magic('html', '', 'click here to say hi!\n')