You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This will print the exception raised by str(instance) on one of the broken instances, and then print the number of good instances between each broken one. Output:
In my production code, the issue also occurs if I pass an instance from Python to native C#/CLR code without doing anything to it in Python (i.e. not triggering a Python exception the way str(instance) does in the repro above). E.g:
instance=Foobar()
# public void SomeMethod(IDisposable arg_foo) { ... }NativeCode.SomeMethod(instance)
In this case, the C# code raises an exception something like this, once in a blue moon: System.InvalidCastException: 'Foobar' value cannot be converted to System.IDisposable
Notes:
IDisposable was just something I grabbed at random for the repro; the issue seems to happen with any interface
With the System.GC.Collect() line in the repro code uncommented, the issue doesn't seem to occur.
In my production code, at least, adding assert System.GC.TryStartNoGCRegion(1) before the affected code seems to make the issue occur more frequently
I put a few debug prints in and what seems to happen here is that the GC handle's target is empty in this case, which is very odd. I'll see whether I can debug this further.
Environment
Details
When a Python class inherits from a .NET interface, I'm very occasionally getting broken instances (once every few 10,000 to 100,000 instantiations):
This will print the exception raised by
str(instance)
on one of the broken instances, and then print the number of good instances between each broken one. Output:In my production code, the issue also occurs if I pass an instance from Python to native C#/CLR code without doing anything to it in Python (i.e. not triggering a Python exception the way
str(instance)
does in the repro above). E.g:In this case, the C# code raises an exception something like this, once in a blue moon:
System.InvalidCastException: 'Foobar' value cannot be converted to System.IDisposable
Notes:
IDisposable
was just something I grabbed at random for the repro; the issue seems to happen with any interfaceWith the
System.GC.Collect()
line in the repro code uncommented, the issue doesn't seem to occur.In my production code, at least, adding
assert System.GC.TryStartNoGCRegion(1)
before the affected code seems to make the issue occur more frequentlyI found Python.exe crashes if __pycache__ directories exist (garbage collection trashed) #481 to be vaguely similar, at least to this outsider
The text was updated successfully, but these errors were encountered: