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

Skip to content

Rebase to pythonnet master #20

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 86 commits into from
Jan 15, 2019
Merged

Rebase to pythonnet master #20

merged 86 commits into from
Jan 15, 2019

Conversation

AlexCatarino
Copy link
Member

No description provided.

den-run-ai and others added 30 commits July 4, 2018 21:21
still need to look at windows case
* fixed bug of method PyString_FromString

* fixup! fixed bug of method PyString_FromString

* removed spaces

* Update appveyor.yml

* Update requirements.txt

* Update conversiontest.cs

* Update test_conversion.py
Travis now has msbuild 15 available, which breaks the no-arg build since it's using the pythonnet.sln which is msbuild 14. Fixed by forcing the use of msbuild 14.

Appveyor on py34 is failing to build psutil; newer python and py27 are using binary releases so the problem doesn't show up. I couldn't figure out how to fix it, so I made it an allowed failure.
The Unity editor unloads the C# domain and creates a new domain every time it recompiles C# sources.

This caused two crashes.
1. After a domain unload, python is now pointing to a bunch of objects whose C# side is now garbage. Solution: Shutdown() the engine on domain reload, which calls Py_Finalize.

2. After a domain unload, Py_Finalize, and a new Py_Intialize, python still keeps pointers in gc for any python objects that were leaked. And pythonnet leaks. This means that python's gc will be calling tp_traverse, tp_clear, and tp_is_gc on types that are implemented in C#. This crashes because the implementation was freed. Solution: implement those calls in code that is *not* released on domain unload. Side effect: we leak a page on every domain unload. I suspect but didn't test that python gc performance will be slightly faster.

Changes required to implement and test:
3. Use python's platform package to determine what we're running on, so we can use the right mmap/mprotect or VirtualAlloc/VirtualProtect routines, the right flags for mmap, and (theoretically) the right native code. Side effect: to port to a new platform requires updating some additional code now.

4. New unit tests. (a) A new test for domain reload. It doesn't run under .NET Core because you can't create and unload a domain in .NET Core. (b) New unit tests to help us find where to add support for new platforms.
filmor and others added 16 commits November 15, 2018 13:43
Convertes System.Decimal to decimal.decimal and vice-versa
Converts System.DateTime and System.TimeSpan to datetime.datetime and datetime.timedelta and vice-versa
DECREF'ing datetime timezone argument when DateTimeKind is Unspecified was causing `Fatal Python error: deallocating None` because the object was set to `Runtime.PyNone`.

Fixed the input to datetime constructor as we were passing milliseconds, where it should be microseconds.
- C# decimal conversion will use C# double and python float due to the
big performance impact of converting C# decimal to python decimal.
@AlexCatarino AlexCatarino deleted the update branch January 15, 2019 18:42
@AlexCatarino AlexCatarino restored the update branch January 15, 2019 18:43
@AlexCatarino AlexCatarino deleted the update branch January 15, 2019 18:43
@AlexCatarino AlexCatarino restored the update branch January 15, 2019 18:43
@AlexCatarino AlexCatarino reopened this Jan 15, 2019
initialized = true;
Exceptions.Clear();

// Make sure we clean up properly on app domain unload.
AppDomain.CurrentDomain.DomainUnload += OnDomainUnload;
Copy link
Member

Choose a reason for hiding this comment

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

is the application and pythonnet running in the same app domain?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. AppDomain.CurrentDomain is QuantConnect.Lean.Launcher.exe when I run Lean.

@jaredbroad jaredbroad merged commit b64fa5f into master Jan 15, 2019
@AlexCatarino AlexCatarino deleted the update branch January 18, 2019 20:14
@AlexCatarino AlexCatarino restored the update branch January 18, 2019 20:14
@AlexCatarino AlexCatarino deleted the update branch January 18, 2019 20:14
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.