This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

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

Created on 2018-05-09 20:43 by Jean-Louis Tamburini, last changed 2022-04-11 14:59 by admin. This issue is now closed.

File name Uploaded Description Edit Jean-Louis Tamburini, 2018-05-15 15:17
Pull Requests
URL Status Linked Edit
PR 7884 merged ZackerySpytz, 2018-06-23 21:37
PR 7888 merged miss-islington, 2018-06-24 03:15
PR 7889 merged miss-islington, 2018-06-24 03:16
Messages (7)
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) * (Python triager) 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().
msg320346 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2018-06-24 03:15
New changeset ea737751b10fff752aafed0231e8a02b82ba365d by Nick Coghlan (Zackery Spytz) in branch 'master':
bpo-33451: Close pyc files before calling PyEval_EvalCode() (GH-7884)
msg320349 - (view) Author: miss-islington (miss-islington) Date: 2018-06-24 03:31
New changeset 56aaef0ddba6275b8043b58433739a64497f33b4 by Miss Islington (bot) in branch '3.7':
bpo-33451: Close pyc files before calling PyEval_EvalCode() (GH-7884)
msg323518 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2018-08-14 13:16
All PRs have been merged (commit message from the 3.6 branch doesn't listed here but PR 7889 has been merged in Closing this as 'fixed'. Please reopen if this issue needs to stay open.
Date User Action Args
2022-04-11 14:59:00adminsetgithub: 77632
2018-08-14 13:16:53berker.peksagsetstatus: open -> closed

nosy: + berker.peksag
messages: + msg323518

resolution: fixed
stage: patch review -> resolved
2018-06-24 03:31:23miss-islingtonsetnosy: + miss-islington
messages: + msg320349
2018-06-24 03:16:43miss-islingtonsetpull_requests: + pull_request7497
2018-06-24 03:15:56miss-islingtonsetpull_requests: + pull_request7496
2018-06-24 03:15:27ncoghlansetmessages: + msg320346
2018-06-23 21:37:51ZackerySpytzsetkeywords: + patch
stage: patch review
pull_requests: + pull_request7493
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