Random Access Violations on shutdown
See original GitHub issueEnvironment
- Pythonnet version: 3.0.0.post1
- Python version: 3.8.10
- Operating System: Windows 11
- .NET Runtime: .NET Framework 472
Details
-
Describe what you were trying to get done.
I am getting random access violations during shutdown in pythonnet. The issue can be re-produced with a C# function as simple as
public static int Add(int a, int b) => a + b;
I get the access violation; however, it is not deterministic at all. Some times, it succeeds as expected, other times I get this. Note that I am upgrading from pythonnet 2.5.2 to pythonnet 3.0.0.post1 so this code used to work. All I am doing is invoking this code from python. I am running this python code that uses pythonnet in pytest. I haven’t seen this when we were using pythonnet 2.5.2.
- If there was a crash, please include the traceback here.
Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at Python.Runtime.Runtime.PyObject_TYPE(BorrowedReference op)
at Python.Runtime.Runtime.NullGCHandles(IEnumerable`1 objects)
at Python.Runtime.Runtime.TryCollectingGarbage(Int32 runs, Boolean forceBreakLoops)
at Python.Runtime.Runtime.Shutdown()
at Python.Runtime.PythonEngine.Shutdown()
at Python.Runtime.Loader.Shutdown(IntPtr data, Int32 size)
Issue Analytics
- State:
- Created a year ago
- Comments:32 (11 by maintainers)
Top Results From Across the Web
Exception Access Violation: What It Is and How to Fix It on ...
Exception Access Violation is an error you may see on your Windows computer when you try to execute a specific program or function....
Read more >Random Access Violations in my code
The access violation occurs in the middle of the whole process - I know because if it was in the end, the progressbar...
Read more >Random crashes occurring error access violation at ...
When using the computer, web browsing and gaming. I am receiving crashes. These happen sometimes when i open games or even at random....
Read more >[SOLVED] – Exception Access Violation Error on Windows
The Exception Access Violation Error on your Windows PC could be a result of enabled UAC or faulty RAM modules. Here are some...
Read more >Random Access Violation Errors - Technical Support
I woke up on Wednesday ready to game and noticed that my game now randomly fails with an Access Violation error:
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes, please add an option to disable the shutdown code completely. I have had cases where simply
Ctrl+C
ing the process caused a .NET stack trace to be printed, which should not be the case. I have tried monkey-patching thepythonnet.unload
function, but it made everything worse, that is, even more annoying stack traces printed to the console.Would this be an appropriate fix?
The fix is simple: remove a possible reference to the currently disposed object from the
reflectedObjects
set. If the item does not exist the Remove is a no-op.I am not entirely sure why a variable
copyForException
is not used in the catch block.