Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why *.pyc files are being deleted when the associated *.py file is deleted

See update at the end.

I am using Ubuntu Linux 11.10, Python 3.

I wrote a Python script which converts some Qt *.ui files to *.py using pyuic4. Then i want to compile the obtained *.py file to *.pyc and delete the *.py file.

For some reason when i delete a converted *.py file, the *.pyc version is also deleted:

try:
    command = 'pyuic4 -o /home/vic/ui_form.py /home/vic/form.ui'
    output = subprocess.check_output(command, shell= True, stderr= subprocess.STDOUT)
except subprocess.CalledProcessError as e:
    print('Failed:', e.output)
else:
    print('Converted %s to %s' % (source, targetName))

# convert *.py to *.pyc and delete the source
source = '/home/vic/ui_form.py'
target = source + 'c' # py -> pyc
py_compile.compile(source, target)
#shutil.copy(target, target + '_') # if uncommented - the *.pyc_ file remains
os.remove(source) # if commented - both *.py and *.pyc files remain, otherwise both deleted (?)

I don't know what's happening (see the comments in the code for additional info).

I thought i would have a hint if i find WHO deletes the file - maybe it's pyuic4?

I there a possibility to monitor which process deletes a file?


UPDATE:

I was debugging step by step. After executing os.remove(source) both files (*.py - source, and *.pyc) are deleted.

Could this be some Python behavior?

like image 208
warvariuc Avatar asked Dec 20 '25 05:12

warvariuc


1 Answers

You can set sysctl -w vm.block_dump=1 to see every file system action in dmesg. (high volume, so disable again afterwards)

like image 78
al. Avatar answered Dec 22 '25 20:12

al.