Jupyter Notebook:Signal仅在主线程中有效,并且内核会反复重启

时间:2018-10-13 17:06:49

标签: python jupyter-notebook

ValueError:创建新笔记本时,仅在主线程中引发信号。然后,它继续重新启动内核。新笔记本显示“内核似乎已经死亡。它将自动重新启动。”几次重启后。 我该如何解决这个问题?

      self.asyncio_loop.run_forever()
      File "d:\program files\python\lib\asyncio\base_events.py", line 340, in run_forever
        raise RuntimeError('Event loop is running.')
    RuntimeError: Event loop is running.
    [I 00:55:49.986 NotebookApp] KernelRestarter: restarting kernel (1/5), keep random ports
    Traceback (most recent call last):
      File "d:\program files\python\lib\runpy.py", line 184, in _run_module_as_main
        "__main__", mod_spec)
      File "d:\program files\python\lib\runpy.py", line 85, in _run_code
        exec(code, run_globals)
      File "d:\program files\python\lib\site-packages\ipykernel\__main__.py", line 3, in <module>
        app.launch_new_instance()
      File "d:\program files\python\lib\site-packages\traitlets\config\application.py", line 658, in launch_instance
        app.start()
      File "d:\program files\python\lib\site-packages\ipykernel\kernelapp.py", line 474, in start
        ioloop.IOLoop.instance().start()
      File "d:\program files\python\lib\site-packages\tornado\platform\asyncio.py", line 132, in start
        self.asyncio_loop.run_forever()
      File "d:\program files\python\lib\asyncio\base_events.py", line 340, in run_forever
        raise RuntimeError('Event loop is running.')
    RuntimeError: Event loop is running.
    [I 00:55:55.990 NotebookApp] KernelRestarter: restarting kernel (1/5), keep random ports
    Traceback (most recent call last):
      File "d:\program files\python\lib\runpy.py", line 184, in _run_module_as_main
        "__main__", mod_spec)
      File "d:\program files\python\lib\runpy.py", line 85, in _run_code
        exec(code, run_globals)
      File "d:\program files\python\lib\site-packages\ipykernel\__main__.py", line 3, in <module>
        app.launch_new_instance()
      File "d:\program files\python\lib\site-packages\traitlets\config\application.py", line 658, in launch_instance
        app.start()
      File "d:\program files\python\lib\site-packages\ipykernel\kernelapp.py", line 474, in start
        ioloop.IOLoop.instance().start()
      File "d:\program files\python\lib\site-packages\tornado\platform\asyncio.py", line 132, in start
        self.asyncio_loop.run_forever()
      File "d:\program files\python\lib\asyncio\base_events.py", line 340, in run_forever
        raise RuntimeError('Event loop is running.')
    RuntimeError: Event loop is running.
    [I 00:56:02.106 NotebookApp] KernelRestarter: restarting kernel (1/5), keep random ports
    Traceback (most recent call last):
      File "d:\program files\python\lib\runpy.py", line 184, in _run_module_as_main
        "__main__", mod_spec)
      File "d:\program files\python\lib\runpy.py", line 85, in _run_code
        exec(code, run_globals)
      File "d:\program files\python\lib\site-packages\ipykernel\__main__.py", line 3, in <module>
        app.launch_new_instance()
      File "d:\program files\python\lib\site-packages\traitlets\config\application.py", line 658, in launch_instance
        app.start()
      File "d:\program files\python\lib\site-packages\ipykernel\kernelapp.py", line 474, in start
        ioloop.IOLoop.instance().start()
      File "d:\program files\python\lib\site-packages\tornado\platform\asyncio.py", line 132, in start
        self.asyncio_loop.run_forever()
      File "d:\program files\python\lib\asyncio\base_events.py", line 340, in run_forever
        raise RuntimeError('Event loop is running.')
    RuntimeError: Event loop is running.
    [I 00:56:08.108 NotebookApp] KernelRestarter: restarting kernel (1/5), keep random ports
    Traceback (most recent call last):
      File "d:\program files\python\lib\runpy.py", line 184, in _run_module_as_main
        "__main__", mod_spec)
      File "d:\program files\python\lib\runpy.py", line 85, in _run_code
        exec(code, run_globals)
      File "d:\program files\python\lib\site-packages\ipykernel\__main__.py", line 3, in <module>
        app.launch_new_instance()
      File "d:\program files\python\lib\site-packages\traitlets\config\application.py", line 658, in launch_instance
        app.start()
      File "d:\program files\python\lib\site-packages\ipykernel\kernelapp.py", line 474, in start
        ioloop.IOLoop.instance().start()
      File "d:\program files\python\lib\site-packages\tornado\platform\asyncio.py", line 132, in start
        self.asyncio_loop.run_forever()
      File "d:\program files\python\lib\asyncio\base_events.py", line 340, in run_forever
        raise RuntimeError('Event loop is running.')
    RuntimeError: Event loop is running.
    [I 00:56:14.121 NotebookApp] KernelRestarter: restarting kernel (1/5), keep random ports
    [W 00:56:14.614 NotebookApp] Timeout waiting for kernel_info reply from 58c4bf98-808e-4253-b3f5-a0a1a540ba83
    ERROR:tornado.general:Uncaught exception in ZMQStream callback
    Traceback (most recent call last):
      File "d:\program files\python\lib\site-packages\zmq\eventloop\zmqstream.py", line 432, in _run_callback
        callback(*args, **kwargs)
      File "d:\program files\python\lib\site-packages\tornado\stack_context.py", line 300, in null_wrapper
        return fn(*args, **kwargs)
      File "d:\program files\python\lib\site-packages\ipykernel\kernelbase.py", line 276, in dispatcher
        return self.dispatch_shell(stream, msg)
      File "d:\program files\python\lib\site-packages\ipykernel\kernelbase.py", line 226, in dispatch_shell
        self.pre_handler_hook()
      File "d:\program files\python\lib\site-packages\ipykernel\kernelbase.py", line 241, in pre_handler_hook
        self.saved_sigint_handler = signal(SIGINT, default_int_handler)
      File "d:\program files\python\lib\signal.py", line 47, in signal
        handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
    ValueError: signal only works in main thread
    ERROR:tornado.general:Uncaught exception in zmqstream callback
    Traceback (most recent call last):
      File "d:\program files\python\lib\site-packages\zmq\eventloop\zmqstream.py", line 450, in _handle_events
        self._handle_recv()
      File "d:\program files\python\lib\site-packages\zmq\eventloop\zmqstream.py", line 480, in _handle_recv
        self._run_callback(callback, msg)
      File "d:\program files\python\lib\site-packages\zmq\eventloop\zmqstream.py", line 432, in _run_callback
        callback(*args, **kwargs)
      File "d:\program files\python\lib\site-packages\tornado\stack_context.py", line 300, in null_wrapper
        return fn(*args, **kwargs)
      File "d:\program files\python\lib\site-packages\ipykernel\kernelbase.py", line 276, in dispatcher
        return self.dispatch_shell(stream, msg)
      File "d:\program files\python\lib\site-packages\ipykernel\kernelbase.py", line 226, in dispatch_shell
        self.pre_handler_hook()
      File "d:\program files\python\lib\site-packages\ipykernel\kernelbase.py", line 241, in pre_handler_hook
        self.saved_sigint_handler = signal(SIGINT, default_int_handler)
      File "d:\program files\python\lib\signal.py", line 47, in signal
        handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
    ValueError: signal only works in main thread
    ERROR:tornado.application:Exception in callback functools.partial(<function wrap.<locals>.null_wrapper at 0x0544FDB0>)
    Traceback (most recent call last):
      File "d:\program files\python\lib\site-packages\tornado\ioloop.py", line 758, in
_run_callback
        ret = callback()
      File "d:\program files\python\lib\site-packages\tornado\stack_context.py", line 300, in null_wrapper
        return fn(*args, **kwargs)
      File "d:\program files\python\lib\site-packages\zmq\eventloop\zmqstream.py", line 536, in <lambda>
        self.io_loop.add_callback(lambda : self._handle_events(self.socket, 0))
      File "d:\program files\python\lib\site-packages\zmq\eventloop\zmqstream.py", line 450, in _handle_events
        self._handle_recv()
      File "d:\program files\python\lib\site-packages\zmq\eventloop\zmqstream.py", line 480, in _handle_recv
        self._run_callback(callback, msg)
      File "d:\program files\python\lib\site-packages\zmq\eventloop\zmqstream.py", line 432, in _run_callback
        callback(*args, **kwargs)
      File "d:\program files\python\lib\site-packages\tornado\stack_context.py", line 300, in null_wrapper
        return fn(*args, **kwargs)
      File "d:\program files\python\lib\site-packages\ipykernel\kernelbase.py", line 276, in dispatcher
        return self.dispatch_shell(stream, msg)
      File "d:\program files\python\lib\site-packages\ipykernel\kernelbase.py", line 226, in dispatch_shell
        self.pre_handler_hook()
      File "d:\program files\python\lib\site-packages\ipykernel\kernelbase.py", line 241, in pre_handler_hook
        self.saved_sigint_handler = signal(SIGINT, default_int_handler)
      File "d:\program files\python\lib\signal.py", line 47, in signal
        handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
    ValueError: signal only works in main threadTraceback (most recent call last):

      File "d:\program files\python\lib\runpy.py", line 184, in _run_module_as_main
        "__main__", mod_spec)
      File "d:\program files\python\lib\runpy.py", line 85, in _run_code
        exec(code, run_globals)
      File "d:\program files\python\lib\site-packages\ipykernel\__main__.py", line 3, in <module>
        app.launch_new_instance()
      File "d:\program files\python\lib\site-packages\traitlets\config\application.py", line 658, in launch_instance
        app.start()
      File "d:\program files\python\lib\site-packages\ipykernel\kernelapp.py", line 474, in start
        ioloop.IOLoop.instance().start()
      File "d:\program files\python\lib\site-packages\tornado\platform\asyncio.py", line 132, in start
        self.asyncio_loop.run_forever()
      File "d:\program files\python\lib\asyncio\base_events.py", line 340, in run_forever
        raise RuntimeError('Event loop is running.')
    RuntimeError: Event loop is running.
    [I 00:56:20.182 NotebookApp] KernelRestarter: restarting kernel (1/5), keep random ports
    WARNING:root:kernel 58c4bf98-808e-4253-b3f5-a0a1a540ba83 restarted
    Traceback (most recent call last):
      File "d:\program files\python\lib\runpy.py", line 184, in _run_module_as_main
        "__main__", mod_spec)
      File "d:\program files\python\lib\runpy.py", line 85, in _run_code
        exec(code, run_globals)
      File "d:\program files\python\lib\site-packages\ipykernel\__main__.py", line 3, in <module>
        app.launch_new_instance()
      File "d:\program files\python\lib\site-packages\traitlets\config\application.py", line 658, in launch_instance
        app.start()
      File "d:\program files\python\lib\site-packages\ipykernel\kernelapp.py", line 474, in start
        ioloop.IOLoop.instance().start()
      File "d:\program files\python\lib\site-packages\tornado\platform\asyncio.py", line 132, in start
        self.asyncio_loop.run_forever()
      File "d:\program files\python\lib\asyncio\base_events.py", line 340, in run_forever
        raise RuntimeError('Event loop is running.')
    RuntimeError: Event loop is running.
    [I 00:56:26.223 NotebookApp] KernelRestarter: restarting kernel (1/5), keep random ports
    WARNING:root:kernel 58c4bf98-808e-4253-b3f5-a0a1a540ba83 restarted
    Traceback (most recent call last):
      File "d:\program files\python\lib\runpy.py", line 184, in _run_module_as_main
        "__main__", mod_spec)
      File "d:\program files\python\lib\runpy.py", line 85, in _run_code
        exec(code, run_globals)
      File "d:\program files\python\lib\site-packages\ipykernel\__main__.py", line 3, in <module>
        app.launch_new_instance()
      File "d:\program files\python\lib\site-packages\traitlets\config\application.py", line 658, in launch_instance
        app.start()
      File "d:\program files\python\lib\site-packages\ipykernel\kernelapp.py", line 474, in start
        ioloop.IOLoop.instance().start()
      File "d:\program files\python\lib\site-packages\tornado\platform\asyncio.py", line 132, in start
        self.asyncio_loop.run_forever()
      File "d:\program files\python\lib\asyncio\base_events.py", line 340, in run_forever
        raise RuntimeError('Event loop is running.')
    RuntimeError: Event loop is running.
    ERROR:tornado.general:Uncaught exception in ZMQStream callback
    Traceback (most recent call last):
      File "d:\program files\python\lib\site-packages\zmq\eventloop\zmqstream.py", line 432, in _run_callback
        callback(*args, **kwargs)
      File "d:\program files\python\lib\site-packages\tornado\stack_context.py", line 300, in null_wrapper
        return fn(*args, **kwargs)
      File "d:\program files\python\lib\site-packages\ipykernel\kernelbase.py", line 276, in dispatcher
        return self.dispatch_shell(stream, msg)
      File "d:\program files\python\lib\site-packages\ipykernel\kernelbase.py", line 226, in dispatch_shell
        self.pre_handler_hook()
      File "d:\program files\python\lib\site-packages\ipykernel\kernelbase.py", line 241, in pre_handler_hook
        self.saved_sigint_handler = signal(SIGINT, default_int_handler)
      File "d:\program files\python\lib\signal.py", line 47, in signal
        handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
    ValueError: signal only works in main thread
    ERROR:tornado.general:Uncaught exception in zmqstream callback
    Traceback (most recent call last):
      File "d:\program files\python\lib\site-packages\zmq\eventloop\zmqstream.py", line 450, in _handle_events
        self._handle_recv()
      File "d:\program files\python\lib\site-packages\zmq\eventloop\zmqstream.py", line 480, in _handle_recv
        self._run_callback(callback, msg)
      File "d:\program files\python\lib\site-packages\zmq\eventloop\zmqstream.py", line 432, in _run_callback
        callback(*args, **kwargs)
      File "d:\program files\python\lib\site-packages\tornado\stack_context.py", line 300, in null_wrapper
        return fn(*args, **kwargs)
      File "d:\program files\python\lib\site-packages\ipykernel\kernelbase.py", line 276, in dispatcher
        return self.dispatch_shell(stream, msg)
      File "d:\program files\python\lib\site-packages\ipykernel\kernelbase.py", line 226, in dispatch_shell
        self.pre_handler_hook()
      File "d:\program files\python\lib\site-packages\ipykernel\kernelbase.py", line 241, in pre_handler_hook
        self.saved_sigint_handler = signal(SIGINT, default_int_handler)
      File "d:\program files\python\lib\signal.py", line 47, in signal
        handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
    ValueError: signal only works in main thread

1 个答案:

答案 0 :(得分:0)

解决了,终于发现有2个jupyter已安装。通过pip卸载一个jupyter之后。笔记本现在可以使用了。