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

run CFRunLoopRun if NSApp:run finishes on its own #9854

Merged
merged 1 commit into from Aug 10, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion IPython/terminal/pt_inputhooks/osx.py
Expand Up @@ -7,6 +7,7 @@

import ctypes
import ctypes.util
from threading import Event

objc = ctypes.cdll.LoadLibrary(ctypes.util.find_library('objc'))

Expand Down Expand Up @@ -97,8 +98,11 @@ def _wake(NSApp):
msg(NSApp, n('postEvent:atStart:'), void_p(event), True)


_triggered = Event()

def _input_callback(fdref, flags, info):
"""Callback to fire when there's input to be read"""
_triggered.set()
CFFileDescriptorInvalidate(fdref)
CFRelease(fdref)
NSApp = _NSApp()
Expand All @@ -111,6 +115,7 @@ def _input_callback(fdref, flags, info):

def _stop_on_read(fd):
"""Register callback to stop eventloop when there's data on fd"""
_triggered.clear()
fdref = CFFileDescriptorCreate(None, fd, False, _c_input_callback, None)
CFFileDescriptorEnableCallBacks(fdref, kCFFileDescriptorReadCallBack)
source = CFFileDescriptorCreateRunLoopSource(None, fdref, 0)
Expand All @@ -130,4 +135,9 @@ def inputhook(context):
return
_stop_on_read(context.fileno())
msg(NSApp, n('run'))

if not _triggered.is_set():
# app closed without firing callback,
# probably due to last window being closed.
# Run the loop manually in this case,
# since there may be events still to process (#9734)
CoreFoundation.CFRunLoopRun()