-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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
Always run the OS X loop even if no windows. #10150
Conversation
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 for working on this one! I'll have a look tomorrow. I'll have to refresh my memory on the last few bugs we worked out on this stuff, in case this is trading a new bug for an old one. |
Appears to work, and isn't related to the previous bugfixes on this tricky one. Thanks! |
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.
Cool! Can the auto-backport copy the milestone, as well? |
Backport PR #10150 on branch 5.x
It could, I added an issue. |
I was using this inputhook in my own prompt_toolkit application. Before this patch, it worked just fine. After this patch, it causes my application to be completely unresponsive to all keyboard input. |
Your suggested code from the commit message works for me. I can't reproduce the original bouncing Dock issue with the Anaconda Python, so I can't say how it affects that. |
Hum, sorry about that. We would need to better understand all the interactions and when to do what. Event loop are hard. |
Oh, scratch that your commit message fix doesn't work (didn't save the file correctly 😳). |
it's ok, GitHub have a delete comment button if needed. |
Well I'm not ashamed of making a mistake. And it already sent the email, so it would just be confusing to you. |
@asmeurer do you have an example that doesn't behave right? |
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. |
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.