Add soft shutdown#958
Conversation
|
Can you explain how does soft shutdown work in more details? |
Sorry, something went wrong.
|
The base concept is, after |
Sorry, something went wrong.
|
I'm unsure how this relates to #957. Seems to be more about improving the GC handling? The prototype that @BadSingleton did was, in implementation, fairly simple (took us a while to figure it out of course):
|
Sorry, something went wrong.
|
Well, Python crash is connect with GC handling, after domain unload, when the GC collect occurred, it will traverse all GC objects, but the memory from old domain has been invalid, any access will result to crash. |
Sorry, something went wrong.
* Keep delegate of Thunk in tp_dict * Remove useless code
* Fix ref error at PythoneEngine.With
…nObject) will not care 'u' on Python2.
…hutdown forcedly * Disable restore objects on default
|
I've summarized my understanding in this document: https://docs.google.com/document/d/1a9OLsdKHXJ6MxHjo0WlVRcfjAiaP5hONNKUKKH6Tr-o I see two PRs that would be easy to pull out of amos' code and check in right now:
I don't yet understand what the gc chains thing is trying to address. I also don't understand how amos handles the modules. I suspect they're related. It seems like amos is turning off python gc for the proxy objects. If that works, we should just turn it all off and then we can eliminate the native code page. But that's yet another PR. There seems to be some refcount fixes as well. If we can get those fixes in separate PRs that makes it easier to review. |
Sorry, something went wrong.
* Drop C module dependency when getting _PyObject_NextNotImplemented * Exception details for SetNoSiteFlag
…mments-2 Soft shutdown review comments 2
And other code review changes
Even if netstandard lacks (for now) the necessary APIs for domain (un)loading, it is still possible to (un)load domains via the Mono C runtime.
In Runtime_data.cs
…e pointer" We Don't support python 2 anymore, but the CI machines may still be using it to build.
Also adds implicit IntPtr conversion operators to simplify their use.
…mments-3 * Remove compile-time check on NETSTANDARD * Extract method `ClearCLRData`
* Fix dead lock occur by calling PyEval_RestoreThread without check * Ignore `CollectOnShutdown` temporarily
Codecov Report
@@ Coverage Diff @@
## master #958 +/- ##
=======================================
Coverage 86.25% 86.25%
=======================================
Files 1 1
Lines 291 291
=======================================
Hits 251 251
Misses 40 40
Flags with carried forward coverage won't be shown. Click here to find out more. Continue to review full report at Codecov.
|
Sorry, something went wrong.
What does this implement/fix? Explain your changes.
An upgraded version for #754
An implementation for #957
Also included some minor fixes.
Still simple and roughly, reset all GC objects by a save state, the old domain objects will be leaking and unaccessible.
Here's my next plan, I think I can replace all the clr objects slots to solid callbacks, that may help the memory leaking.
How to use: use
PythonEngine.Initialize(softShutdown: true)for startup.Updated Details:
RuntimeState.ShouldRestoreObjects, and modules which not insys.modulesafter just call initial CPython will be remove fromsys.moduleson soft shutdown mode.tp_traveseandtp_clearto release their sub objects, then useSlotsHolder.ReleaseTypeSlotsreset their slots.Points can be optimize for the above mechanism:
tp_traveseandtp_clearare not necessary for all time, they will become overhead for CPython's GC, maybe we can just use C# methods instead.SlotsHolderis not suitable because it also handle the memory release.tp_is_gcand some other slots are no need to be override at start, they can inherit fromPyType_Typeby default.Interopdo not holding the delegate objects by callingGetThunkanymore, theSlotsHolderwill take care of them.__import__will restore at shutdown.Does this close any currently open issues?
#957
Any other comments?
Checklist
Check all those that are applicable and complete.
AUTHORSCHANGELOG