Always run the OS X loop even if no windows. #10150
Otherwise this can trigger infinite Python-Icon-In-Dock bouncing. See ipython#10137. I will guess that this is because application on OS X may not have windows and still need to process events. It may be that an alternative is to run the loop only once the first time, but I'm unsure. at_least_once = False def inputhook(context): """Inputhook for Cocoa (NSApp)""" NSApp = _NSApp() window_count = msg( msg(NSApp, n('windows')), n('count') ) if not window_count and not at_least_once: at_least_once = True 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 (ipython#9734) CoreFoundation.CFRunLoopRun() Closes ipython#10137
Thanks. Let's try to autobackport. @meeseeksdev backport to 5.x…
On Fri, Jan 13, 2017 at 1:36 AM, Min RK ***@***.***> wrote: Merged #10150 <#10150>. — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub <#10150 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AAUez5SZHOQ_7-Hcjth_PTqd8IVo6MQ9ks5rR0WrgaJpZM4LiPR4> .
Otherwise this can trigger infinite Python-Icon-In-Dock bouncing. See 10137. I will guess that this is because application on OS X may not have windows and still need to process events. It may be that an alternative is to run the loop only once the first time, but I'm unsure. ---- Ping minrk : I have no clue what I am doing.
Even a dead simple prompt-toolkit shell reproduces the issue:
#!/usr/bin/env pythonw # Basic REPL from traceback import print_exc from prompt_toolkit.shortcuts import prompt, create_eventloop from IPython.terminal.pt_inputhooks.osx import inputhook _globals = _locals = globals().copy() while True: command = prompt(">>> ", eventloop=create_eventloop(inputhook)) try: res = eval(command, _globals, _locals) print(repr(res)) except SyntaxError: try: exec(command, _globals, _locals) except BaseException as e: print_exc() except BaseException as e: print_exc()
With the latest IPython, the shell hangs at startup. It doesn't accept any input, and you have to kill it with
If you use an IPython before this change, it works perfectly. Here's how I've been testing "perfectly", running this at the command line:
>>> import matplotlib >>> matplotlib.interactive(True) None >>> import matplotlib.pylab as plt >>> plt.plot([1, 2]) [<matplotlib.lines.Line2D object at 0x10e09db70>] >>>
Things it should do:
Ideally, I could just import this code directly from IPython (for now, I have copied the code without this change), although I understand that IPython only needs to support IPython. I realise that it works fine in IPython itself, but I'd like at least to understand why. Plus it sounds like you weren't really sure about this change to begin with, so maybe there is something wrong with it, even from the IPython side.