Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix issue with PyPy on macOS #12629

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

Merged
merged 2 commits into from
Oct 25, 2018
Merged

Fix issue with PyPy on macOS #12629

merged 2 commits into from
Oct 25, 2018

Conversation

Mottl
Copy link
Contributor

@Mottl Mottl commented Oct 25, 2018

This PR fixes the issue with PyOS_InputHook variable that is not defined in PyPy implementation:

src/_macosx.m:280:5: error: use of undeclared identifier 'PyOS_InputHook'
PyOS_InputHook = wait_for_stdin;
^

p.s.
The corresponding issue in PyPy bug tracking is https://bitbucket.org/pypy/pypy/issues/2327

@mattip
Copy link
Contributor

mattip commented Oct 25, 2018

A little background, copied from the PyPy issue:

PyOS_InputHook function is exposed in CPython's pythonrun.h, and documented in https://docs.python.org/3/c-api/veryhigh.html. It is used in CPython's builtin tkinter and readline modules.

PyPy uses a pure-python readline implementation, and its set_pre_input_hook function is not implemented.

The relevant code path in tkinter (EnableEventHook and DisableEventHook) is commented out on PyPy. Other platforms perform properly without the hook, I do not know why the MacOS platform uses it on matplotlib.

Copy link
Member

@jklymak jklymak left a comment

Choose a reason for hiding this comment

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

This seems fine. However, I'm curious why we need these input hooks? What do they do, and why do we need them in the first place? Maybe they are obsolete, and can be removed for both pypy and cpython?

@mattip
Copy link
Contributor

mattip commented Oct 25, 2018

My guess is they were needed at one point to allow the tkinter event loop and the REPL event loop to play nicely. But then why were they MacOS only, unless at one point python vendored a broken version of tk on that platform?

Maybe someone with the oldest python and MacOS matplotlib supports could verify the terminal and the canvas are both responsive after removing the callback

@jklymak
Copy link
Member

jklymak commented Oct 25, 2018

Ok away from computer but maybe we should merge this as fixing pypy and then open the rest as a separate issue.

@Mottl
Copy link
Contributor Author

Mottl commented Oct 25, 2018

@mdehoon, could you comment?

@tacaswell tacaswell modified the milestones: v3.0.x, v3.1 Oct 25, 2018
Copy link
Member

@tacaswell tacaswell left a comment

Choose a reason for hiding this comment

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

Pending on OSX developer confirming that this still works as expected on cpython.

Copy link
Member

@jklymak jklymak left a comment

Choose a reason for hiding this comment

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

I can't see any problems w/ the macosx backend when I include this change, but I didn't test to death..

@jklymak jklymak merged commit 921d4f4 into matplotlib:master Oct 25, 2018
@mdehoon
Copy link
Contributor

mdehoon commented Oct 29, 2018

This is very tricky stuff; the backend may seem to work fine but you may notice problems later.
The fundamental problem here is that Python does not support event loops. PyOS_InputHook allows one C extension (e.g. the MacOSX backend) to run an event loop, but this may break if there are more than one C extensions that need an event loop (e.g. the MacOSX backend and Tkinter). One thing to check for is if the CPU usage goes up to 100%.

@jklymak
Copy link
Member

jklymak commented Oct 29, 2018

Thanks @mdehoon. I checked and we definitely need these hooks for the non pypy work.

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.

5 participants