Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clean exit from eventloops #290

Merged
merged 3 commits into from
Dec 19, 2017
Merged

clean exit from eventloops #290

merged 3 commits into from
Dec 19, 2017

Conversation

minrk
Copy link
Member

@minrk minrk commented Dec 15, 2017

When any eventloop is running, ipykernel doesn't exit cleanly because we don't stop the main eventloop, we just stop tornado, which isn't running anymore when the eventloop is active. It turns out we have been relying on jupyter-client forcibly terminating kernels that don't shutdown promptly after a polite request.

To solve this, eventloop.exit_hook is added and should be called when exit is requested (the same event where we have been stopping tornado should now stop both eventloops if they are running).

closes #274
closes #282

TODO:

  • qt
  • asyncio
  • cocoa
  • gtk
  • wx
  • tk

cc @jbweston and @basnijholt for testing

and implement for asyncio, qt

still todo: wx, tk, gtk, cocoa
@minrk minrk changed the title [WIP] clean exit from eventloops clean exit from eventloops Dec 15, 2017
Calls NSApp / CoreFoundation APIs via ctypes.
"""

# cribbed heavily from IPython.terminal.pt_importhooks.osx
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

importhooks -> inputhooks

Removes reliance on matplotlib for Cocoa eventloop integration

mostly copied from pt_inputhooks/osx, with changed wake logic:

- wake on timer instead of stdin FD
- fix stopping of CFRunLoop when no NSApp is running
@basnijholt
Copy link

Thanks, it seems to fix the specific issue raised in #274.

however, restarting a kernel with this still takes a very long time:

import concurrent.futures
import asyncio

executor = concurrent.futures.ProcessPoolExecutor()
ioloop = asyncio.get_event_loop()

def simple_function(x):
    import time
    time.sleep(10000)
    return x

tsk = ioloop.run_in_executor(executor, simple_function, 0)

@minrk
Copy link
Member Author

minrk commented Dec 19, 2017

Thanks!

@minrk minrk merged commit 17bd060 into ipython:master Dec 19, 2017
@minrk
Copy link
Member Author

minrk commented Dec 19, 2017

@basnijholt let's investigate slow restart in a separate Issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Event loop problem on Mac OS X asyncio and concurrent.futures.ProcessPoolExecutor prevent kernel restarts
4 participants