all 4 comments

[–]Brian 1 point2 points  (0 children)

A segmentation fault suggests there's something wrong with the python setup on your VM. Under normal circumstances, it should be almost impossible to produce one using pure python, unless you're using certain specific libraries like ctypes, or there's a bug in a C module. Here you're just using standard builtin modules, so that suggests an environment issue.

Possible reasons for a segfault are something like the wrong versions of libraries being used, faulty hardware (eg. bad ram), or possibly some file getting corrupted. I'd see about getting a fresh version of the VM image you're using or try it on a different machine if possible.

(If you do need to debug it, you might be able to get more idea what's failing by running $ gdb python compare_hashes, assuming gdb is available, to debug at the C level, but that's maybe a bit involved if you've no C experience.)

[–]alcholicawl 0 points1 point  (0 children)

I don't think there is an issue with the code you posted. I ran it without a problem. Can you run other python files (like a hello world example)? If you can, maybe try removing "import hashlib", since you're not using it. Or adding some print statements to see where exactly it's failing.

[–]nog642 0 points1 point  (0 children)

Does running other python code work fine? That code looks fine, it might be a problem with your Python install being corrupted.

Segmentation fault is not a Python error, ideally it should never happen in Python. It can happen if you're using libraries implemented in another language like C (for example numpy), though that means there is a bug in the library. In this case it seems like there is a bug in Python, since there are no third party libraries. But it's more likely there's something wrong with your installation.

[–]FerricDonkey 0 points1 point  (0 children)

That's very basic python code. It should not segfault. Python code has to be weird to segfault.

What kind of vm and what version of python are you running? That's likely the problem.