-
Notifications
You must be signed in to change notification settings - Fork 748
Using String.Format crashes inside pythonnet #1642
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
Comments
I can't reproduce this in the current alpha. Please provide the exact commit of pythonnet that you are running against and the exact project that reproduces the error. Also, please do not open another issue (this is the same as #1641 already). Edit this one, upload things here and reopen the issue afterwards. |
im using the master branch PS: another branch https://github.com/QuantConnect/pythonnet works fine with String.Format |
System.AccessViolationException: 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'
|
I can confirm this reproduces. I believe the reason is that we no longer automatically convert Instead, you should do from System import Int32, String
String.Format('{0},{1}', Int32(1), Int32(2)) In general though this was always a problem with any Python objects passed to methods like this. In my TensorFlow binding for that reason I wrap all However, I do not think it is a good approach for the core library. If somebody wants to autoacquire GIL on all Python object accesses, we can provide a guidance on how to set it up. @filmor thoughts? P.S. keeping open until we make it less surprising, or at least document it. |
Hmm, this is not good. It should not be possible to crash the interpreter with a simple thing like this. We should enforce safe operation of all .NET methods that |
@filmor anything will crash the interpreter without acquiring GIL. |
I am well aware of that :). I just think that it shouldn't be possible to crash the interpreter (easily) from within Python. |
Well, checking if we have GIL is pretty expensive (would slow down all members in Maybe we could make calling .NET methods safe from Python by default, and have String.Format('{0},{1}', 1, 2) # this would be OK
clr.no_gil(String.Format)('{0},{1}', 1, 2) # would crash as in the current issue But frankly I think we should just keep the current behavior, or add |
Any conclusions with this issue? Are we going to leave it as it is or alter the usage of such case? |
I definitely want to have this fixed before we consider releasing an rc, but I won't think about this over the holidays :) |
@sekkit regardless of what we decide, you should be using one of the samples I provided above depending on who's formatting abilities you need, .NET (use |
One option is to have a debug build that would fail an assertion or raise an exception upon any attempt to call PyObject methods without GIL. In NuGet it could be sufficient to suffix version with -debug I think. Not sure about PyPi. |
I don't think that would be a good idea. There is no need to do this in a separate build, we can pass the respective information dynamically. Checking a |
We decided that we are going to GIL-protect all overridden |
Environment
Details
How to reproduce(with project Console.vsproj): @filmor
The text was updated successfully, but these errors were encountered: