Windows fatal exception: access violation

Lately I’ve been getting the error from the title. I’ve googled it, but couldn’t find anything useful. I’m using python 3.9.5 and I’m packing my app using pyarmor + pyinstaller. I’ve been using these tools for a very long time and haven’t seen this error. I will post the tracebacks that I’m getting (note that they are from completely different parts of the app), but not the source code or a minimal example (the codebase is huge, and I cannot produce a minimal example just yet).

My questions are:

  1. What does this error mean exactly?
  2. How do I debug the exact cause of it?

In the CPython tests I was able to find the following:

So, one cause of this error can be that a DLL function is called with invalid arguments.

Also it seems that a more general (python unrelated) identifier of this error is EXCEPTION_ACCESS_VIOLATION.

And then a more general name for this error (windows unrelated) is “Memory Access Violation”. If this is correct, I can now google what it means.

The virtual address space of a process is allocated and manged in pages (typically 4 KiB blocks). A page can allow a combination of read, write, and execute access, or it may allow no access at all, or no access to user-mode code (i.e. a page in kernel space). If an attempt to access an address in memory fails because the address isn’t allocated or because the type of access isn’t allowed for the page in which it resides, the Windows kernel raises an access violation exception on the faulting thread. Tracking down the cause usually requires testing a debug build, attaching a native debugger to the process, and running with special options such as full page-heap protection. Note that the immediate problem of the access violation may only be a symptom of a bug that leads to a bad pointer value, which could be indirectly from stack or heap corruption.

OS exceptions generally are unrelated to Python runtime exceptions. If an OS exception isn’t handled at a low level by the interpreter or an extension module, the process crashes hard. The _ctypes extension module has a structured exception handler (SEH) that raises OSError if an OS exception occurs during an FFI function call. This is what gets tested by the test_SEH() function that you referenced. The test calls GetModuleHandleA() with an invalid address in order to intentionally trigger an access violation exception.

Thanks a lot for the detailed explanation. I’m not experienced with many things that you’re talking about, but your answer gave me some useful insight. I’m now thinking of one possible problem in my particular case and will try to test it.