Skip to content

Drop support for PyPy < 7.3.1 and clean up old PyPy workarounds #2456

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 4 commits into from
Oct 5, 2020

Conversation

YannickJadoul
Copy link
Collaborator

@YannickJadoul YannickJadoul commented Sep 2, 2020

Commit by commit, let's test which parts can go and make tests succeed, and which preprocessor branches we'll need to keep.

Suggestions/commits welcome.

Closes #2436.

@bstaletic
Copy link
Collaborator

This is a peculiar piece of code...

https://github.com/pybind/pybind11/blob/master/include/pybind11/pytypes.h#L730-L736

Add to that #996

@bstaletic
Copy link
Collaborator

docs/intro.rst and docs/advanced/misc.rst have references to PyPy 5.7 and PyPy 5.9, respectively.

@YannickJadoul
Copy link
Collaborator Author

Good catch, @bstaletic! I was going to tell you your can just push to this branch if you want, but I guess you can't. I gave you permissions on my fork now, though. So feel free to... (Feel free to not do that as well, btw! I can get to it later this weekend.)

@henryiii
Copy link
Collaborator

henryiii commented Sep 5, 2020

but I guess you can't

Can't all maintainers edit your branch, since it's a PR here? Or did you uncheck that option?

@YannickJadoul
Copy link
Collaborator Author

Can't all maintainers edit your branch, since it's a PR here? Or did you uncheck that option?

No, it's checked, but @bstaletic is (officially) not a maintainer.

PyPy (at least version 5.9) does not garbage collect objects when the
interpreter exits. An alternative approach (which also works on CPython) is to use
the :py:mod:`atexit` module [#f7]_, for example:
PyPy does not garbage collect objects when the interpreter exits. An alternative
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We might want to re-confirm, this, though. I did not do that, yet.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We have tests for that. Some tests explicitly call gc.collect() more than once because of PyPy, so it shouldn't be hard to verify.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll give it a quick try, but it's actually documented: https://doc.pypy.org/en/latest/cpython_differences.html#differences-related-to-garbage-collection-strategies

Last note: CPython tries to do a gc.collect() automatically when the program finishes; not PyPy. (It is possible in both CPython and PyPy to design a case where several gc.collect() are needed before all objects die. This makes CPython’s approach only work “most of the time” anyway.)

Should we add this to the docs, or are we fine as is?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

(I actually can't find any tests on the garbage collector passing by when the interpreter exits, though. So not sure how to apply @bstaletic's suggestion.)

Copy link
Collaborator

Choose a reason for hiding this comment

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

What about calling PyGC_Collect()? Would that work across the board?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good plan, but seems PyPy doesn't have PyGC_Collect :-(

Copy link
Collaborator

Choose a reason for hiding this comment

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

Other than gc.collect(), which isn't C, there's PyGC_Collect() and a bunch of "didn't mean to make it public" functions that got removed in python 3.9. On the other hand PyGC_Collect() was never documented.

Conclusion: CPython is a horrible mess.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The PyPy devs, struggling to keep up with massive amounts of C API every release, are the last ones you need to convince of that statement, I'm afraid ;-)

@YannickJadoul
Copy link
Collaborator Author

Thanks, @bstaletic! Fixed those extra PyPy reference, and rebased so that we can take advantage of #2462.

@YannickJadoul
Copy link
Collaborator Author

Reminder to ourselves: #2436 (comment)

Copy link
Collaborator

@rwgk rwgk left a comment

Choose a reason for hiding this comment

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

This PR was included in Google-global testing: no issues found.

@YannickJadoul YannickJadoul changed the title [WIP] Drop support for PyPy < 7.3.1 and clean up old PyPy workarounds Drop support for PyPy < 7.3.1 and clean up old PyPy workarounds Oct 5, 2020
@YannickJadoul YannickJadoul marked this pull request as ready for review October 5, 2020 13:54
@henryiii henryiii merged commit 1411207 into pybind:master Oct 5, 2020
@github-actions github-actions bot added the needs changelog Possibly needs a changelog entry label Oct 5, 2020
@YannickJadoul YannickJadoul deleted the pypy-update branch October 5, 2020 14:48
@henryiii henryiii removed the needs changelog Possibly needs a changelog entry label Oct 9, 2020
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.

Explicit minimum supported PyPy?
4 participants