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

Removed ShutdownMode. Now always behaves like original Reload #1638

Merged
merged 4 commits into from Dec 25, 2021

Conversation

lostmsu
Copy link
Member

@lostmsu lostmsu commented Dec 20, 2021

What does this implement/fix? Explain your changes.

This removes all shutdown modes, except Reload (which you don't need to specify, because it is the only one left).

This means Python C runtime is never actually shut down when .NET calls PythonEngine.Shutdown(). Instead, anything from .NET exposed to Python before Shutdown becomes unavailable until PythonEngine.Initialize() is called again (which can be done from a different AppDomain).

Any other comments?

Also in this change:

  • dropped Python 3.6 support
  • fixed Python derived types not being decrefed when an instance is deallocated
  • reduced time and amount of storage needed for runtime reload
  • removed circular reference loop between Type <-> ConstructorBinding(s)
  • exposed Runtime.TryCollectingGarbage

A review from @amos402 would be welcome

@lostmsu lostmsu force-pushed the cleanup/ShutdownModes branch 3 times, most recently from 7ff467a to 7ab2bfc Compare December 20, 2021 21:11
.github/workflows/main.yml Outdated Show resolved Hide resolved
@lostmsu
Copy link
Member Author

lostmsu commented Dec 20, 2021

@filmor looks like I got tests to pass, so this is ready.

@lostmsu lostmsu marked this pull request as ready for review December 20, 2021 23:39
@lostmsu lostmsu added this to the 3.0.0 milestone Dec 21, 2021
@lostmsu lostmsu force-pushed the cleanup/ShutdownModes branch 2 times, most recently from 3157cf5 to 5113257 Compare December 21, 2021 07:14
src/runtime/pythonengine.cs Outdated Show resolved Hide resolved
src/runtime/pytype.cs Outdated Show resolved Hide resolved
}
else
{
ResetPyMembers();
if (mode != ShutdownMode.Extension)
{
Py_Finalize();
Copy link
Member

Choose a reason for hiding this comment

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

This is my only real gripe with this: Embedders would not be able to finalise the Python runtime at all anymore. Maybe we should provide this (Shutdown() + Py_Finalize()) as a possible footgun with a long name?

Copy link
Member Author

Choose a reason for hiding this comment

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

We can always add it if there is a strong request. Instead what happened is people opening bugs about crashes after restarting runtime because NumPy does not support it. I'd rather avoid it.

Moreover, the behavior of the whole thing when either of runtimes is shut down completely is pretty much undefined.

src/runtime/runtime.cs Outdated Show resolved Hide resolved
@lostmsu lostmsu force-pushed the cleanup/ShutdownModes branch 2 times, most recently from 8081238 to 8a093c2 Compare December 21, 2021 17:41
… is an equivalent of `ShutdownMode.Reload`

also in this change:
- fixed Python derived types not being decrefed when an instance is deallocated
- reduced time and amount of storage needed for runtime reload
- removed circular reference loop between Type <-> ConstructorBinding(s)
+ exposed Runtime.TryCollectingGarbage
clearing GCHandle from an instance of Python derived type would drop the last reference to it, so it was destroyed without being removed from reflectedObjects collection
@lostmsu
Copy link
Member Author

lostmsu commented Dec 24, 2021

@filmor I am waiting for an explicit approval or more comments

@lostmsu lostmsu merged commit ec8b69f into pythonnet:master Dec 25, 2021
@lostmsu lostmsu deleted the cleanup/ShutdownModes branch December 25, 2021 18:22
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.

None yet

2 participants