cutter/src/python/cutter_jupyter.py

51 lines
1.2 KiB
Python
Raw Normal View History

2018-02-09 15:48:02 +00:00
import sys
import threading
import time
from notebook.notebookapp import *
class CutterNotebookApp(NotebookApp):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.thread = None
def start(self):
""" see NotebookApp.start() """
super(NotebookApp, self).start()
self.write_server_info_file()
self.thread = threading.Thread(target=self.run)
2018-02-09 15:48:02 +00:00
self.thread.start()
def run(self):
self.io_loop = ioloop.IOLoop.current()
if sys.platform.startswith('win'):
# add no-op to wake every 5s
# to handle signals that may be ignored by the inner loop
pc = ioloop.PeriodicCallback(lambda: None, 5000)
pc.start()
try:
self.io_loop.start()
except KeyboardInterrupt:
self.log.info(_("Interrupted..."))
finally:
self.remove_server_info_file()
self.cleanup_kernels()
def stop(self):
super().stop()
self.thread.join()
@property
def url_with_token(self):
return url_concat(self.connection_url, {'token': self.token})
def start_jupyter():
app = CutterNotebookApp()
app.initialize()
app.start()
return app