Can a PYC File Become Corrupt?

I have a long running PYC file that suddenly stopped working. I initially suspected it had encountered a combination of data I had not anticipated. However, when I manually ran the file I could not CNTL-C out of it.

The PYC is stored on an external USB drive formatted EXT4.

I fixed the problem by recompiling the PYC.

I suspect I may have a bad block on the USB but because I could not CNTL-C out of the PYC I wanted to ask if there was any Python related I could check.


Yes, any file can become corrupted. A PYC doesn’t have a checksum, so you won’t necessarily know.

Exactly what the problem was, resulting in sigint failing, would be hard to pin down. You would have to try unmarshaling the module and seeing if there’s corrupt code in there. It’s unlikely to be particularly useful, but could be a fun exploration.

1 Like

May be the hardware problem caused the kernel to lockup the process stopping SIGINT working.

You may find errors in the system journal (assuming a linux) showing why.

In such cases processes lose control and cannot do anything.

Thanks Chris and Barry. This is the first time it has occurred so I think I’ll wait to see if it replicates itself on another PYC.

I forgot to mention these are all running in SYSTEMD but I replicated the problem running it manually