New submission from tzickel:

I had a non-reproducible issue occur a few times in which python 2.7.9 would 
produce .pyc files with empty code objects on a network drive under windows. 
The .pyc might have been created due to intermittent network errors that are 
hard to reproduce reliably. The .pyc files would override the previous correct 
.pyc files that existed in the same place.

The incorrect .pyc is a valid file, but instead of having the code object of 
the original .py file compiled, it would have the code object of an empty .py 
file. Python would then go on to use the incorrect .pyc file until it is 
manually deleted.

This peculiar .pyc files got me thinking about how cpython can produce such an 
incorrect .pyc file instead of failing.

The main issue here is that getc function, returns EOF both on EOF and on file 
error. It seems as if the tokenizer starts reading the file stream, and gets an 
EOF directly, it would not check if it resulted from actually reading an empty 
file or because of an file error, and happily return an empty AST which would 
be then compiled to a bad empty code .pyc instead of aborting the process 
because of an file error.

----------
messages: 250556
nosy: tzickel
priority: normal
severity: normal
status: open
title: Python can sometimes create incorrect .pyc files
type: behavior
versions: Python 2.7

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue25083>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to