Fix Jupyter for macOS

This commit is contained in:
Florian Märkl 2018-03-06 19:40:24 +01:00
parent 1d583fe441
commit 47d9990f84
2 changed files with 27 additions and 13 deletions

View File

@ -34,7 +34,10 @@ class IPyKernelInterfaceKernel:
self._thread.join() self._thread.join()
self._app.heartbeat.join() self._app.heartbeat.join()
self._app.iopub_thread.stop() self._app.iopub_thread.stop()
self._app.kernel.shell.history_manager.save_thread.stop() try:
self._app.kernel.shell.history_manager.save_thread.stop()
except AttributeError:
pass
zmq.Context.instance().destroy() zmq.Context.instance().destroy()
# successful if only the main thread remains # successful if only the main thread remains
return len(threading.enumerate()) == 1 return len(threading.enumerate()) == 1
@ -69,6 +72,8 @@ def launch_ipykernel(argv):
app = CutterIPKernelApp.instance() app = CutterIPKernelApp.instance()
def run_kernel(): def run_kernel():
import asyncio
asyncio.set_event_loop(asyncio.new_event_loop())
app.kernel_class = CutterIPythonKernel app.kernel_class = CutterIPythonKernel
# app.log_level = logging.DEBUG # app.log_level = logging.DEBUG
app.initialize(argv[3:]) app.initialize(argv[3:])

View File

@ -1,6 +1,6 @@
import signal import asyncio
import time import queue
from jupyter_client.ioloop import IOLoopKernelManager from jupyter_client.ioloop import IOLoopKernelManager
from notebook.notebookapp import * from notebook.notebookapp import *
import cutter_internal import cutter_internal
@ -73,22 +73,18 @@ def kernel_manager_factory(kernel_name, **kwargs):
class CutterNotebookApp(NotebookApp): class CutterNotebookApp(NotebookApp):
def __init__(self, **kwargs): def __init__(self, **kwargs):
super().__init__(**kwargs)
self.thread = None self.thread = None
self.io_loop = None
super().__init__(**kwargs)
def start(self): def start(self):
""" see NotebookApp.start() """ """ see NotebookApp.start() """
self.kernel_manager.kernel_manager_factory = kernel_manager_factory self.kernel_manager.kernel_manager_factory = kernel_manager_factory
super(NotebookApp, self).start() super(NotebookApp, self).start()
self.write_server_info_file() self.write_server_info_file()
self.thread = threading.Thread(target=self.run)
self.thread.start()
def run(self):
self.io_loop = ioloop.IOLoop.current() self.io_loop = ioloop.IOLoop.current()
if sys.platform.startswith('win'): if sys.platform.startswith('win'):
# add no-op to wake every 5s # add no-op to wake every 5s
@ -107,16 +103,29 @@ class CutterNotebookApp(NotebookApp):
super().stop() super().stop()
self.thread.join() self.thread.join()
def init_signal(self):
# This would call signal.signal(signal.SIGINT, signal.SIG_IGN)
# Not needed in supinterpreter.
pass
@property @property
def url_with_token(self): def url_with_token(self):
return url_concat(self.connection_url, {'token': self.token}) return url_concat(self.connection_url, {'token': self.token})
def start_jupyter(): def start_jupyter():
app = CutterNotebookApp() q = queue.Queue()
app.initialize()
app.start() def start_jupyter_async():
return app asyncio.set_event_loop(asyncio.new_event_loop())
app = CutterNotebookApp()
# app.log_level = logging.DEBUG
app.initialize()
q.put(app)
app.start()
threading.Thread(target=start_jupyter_async).start()
return q.get()
if __name__ == "__main__": if __name__ == "__main__":