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?
source=target- so target is your .py initially? Where does this get initialised? And why do you havetargetandtargetName?strace -fhelped - it showed theunlinkcalls, but only*.pyfiles where deleted. could there be a race condition, that compiling *.py -> *.pyc is not finished while *.py is being deleted and *.pyc is also deleted by OS?