Title: Start pyc file lock the file
Type: behavior Stage:
Components: Interpreter Core Versions: Python 3.8, Python 3.7, Python 3.6
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Jean-Louis Tamburini, brett.cannon, eric.snow, eryksun, ncoghlan, paul.moore, steve.dower, tim.golden, zach.ware
Priority: normal Keywords:

Created on 2018-05-09 20:43 by Jean-Louis Tamburini, last changed 2018-05-16 17:00 by eryksun.

File name Uploaded Description Edit Jean-Louis Tamburini, 2018-05-15 15:17
Messages (4)
msg316330 - (view) Author: Jean-Louis Tamburini (Jean-Louis Tamburini) * Date: 2018-05-09 20:43
Python v3.6.4:d48eceb
Windows 10.0.16299

I search on Internet and I don't find why Python Interpreter (v3.6.4) do that. With python 2.7, I don't have this "problem".

When I launch script like : 
While the execution, I can rename/modify the file "". 

But, when I compile the file to .pyc (with py_compile with an another script), and I launch the pyc like :
c:\Python364\python.exe dummy.pyc
While the execution, I CAN'T rename/modify the file because is locked by Python Interpreter. 

It's normal ?
msg316667 - (view) Author: Jean-Louis Tamburini (Jean-Louis Tamburini) * Date: 2018-05-15 15:17
Same for python v3.6.5:f59c0932b4
msg316832 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2018-05-16 16:24
There's no specific reason as to why that would happen as no files are kept open after importing is finished.
msg316843 - (view) Author: Eryk Sun (eryksun) * Date: 2018-05-16 17:00
In Python/pythonrun.c, PyRun_SimpleFileExFlags() reopens the PYC file in binary mode, passes it to run_pyc_file(), and only closes it after executing the script. The file should instead be closed in run_pyc_file(), before calling PyEval_EvalCode().
Date User Action Args
2018-05-16 17:00:04eryksunsetnosy: + eryksun

messages: + msg316843
versions: + Python 3.7, Python 3.8
2018-05-16 16:24:58brett.cannonsetmessages: + msg316832
2018-05-15 22:21:30pitrousetnosy: + brett.cannon, paul.moore, ncoghlan, tim.golden, eric.snow, zach.ware, steve.dower
2018-05-15 15:17:03Jean-Louis Tamburinisetfiles: +

messages: + msg316667
2018-05-09 20:43:58Jean-Louis Tamburinicreate