Issue 3279: import of site.py fails on startup (original) (raw)

Created on 2008-07-04 03:40 by rupole, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
import-site.patch amaury.forgeotdarc,2008-08-25 09:32
different_order.patch benjamin.peterson,2008-08-25 14:37
make_modules_builtin.patch benjamin.peterson,2008-09-05 22:14
make_modules_builtin2.patch benjamin.peterson,2008-09-05 22:47
Messages (17)
msg69240 - (view) Author: Roger Upole (rupole) Date: 2008-07-04 03:40
In pythonrun.c, initstdio injects 'open' into builtins. However, initsite is called before initstdio and site.py uses open. Running with -v, this traceback is printed: Traceback (most recent call last): File "j:\python30\lib\site.py", line 518, in main() File "j:\python30\lib\site.py", line 501, in main known_paths = addsitepackages(known_paths) File "j:\python30\lib\site.py", line 281, in addsitepackages addsitedir(sitedir, known_paths) File "j:\python30\lib\site.py", line 178, in addsitedir addpackage(sitedir, name, known_paths) File "j:\python30\lib\site.py", line 141, in addpackage f = open(fullname, "rU") NameError: global name 'open' is not defined
msg69252 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2008-07-04 11:47
This happens if the site-packages directory contains a .pth file. This was unnoticed because the usual message 'import site' failed; use -v for traceback is never printed: sys.stderr is empty before the call to initstdio().
msg71913 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2008-08-25 09:32
Attached patch writes the "'import site' failed" message to libc stderr instead of sys.stderr, which does not exist at this point. The initial problem still remains: site.py cannot use the "open" builtin.
msg71922 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-08-25 13:40
We could: 1. Use _fileio._FileIO directly. 2. Use os.open. 3. Initialize the stdio streams before importing site. This seems like the best option, although I haven't run all the tests yet.
msg71928 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-08-25 14:37
Here's my patch for the problem.
msg71931 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2008-08-25 14:54
Well, it would be interesting to know why r62778 has exactly the opposite move. Alexandre, do you remember doing it?
msg71933 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-08-25 15:02
It was probably done so that importing _bytesio would actually work in io. IMO, it would be better to just compile _bytesio and _stringio into the python binary.
msg71935 - (view) Author: Alexandre Vassalotti (alexandre.vassalotti) * (Python committer) Date: 2008-08-25 15:11
Benjamin is right. site.py imports the io module before _bytesio and _stringio are available for import. Thus the python version of BytesIO and StringIO is always used. There is an old thread about the issue at http://mail.python.org/pipermail/python-3000/2007-December/011569.html As for compiling _bytesio and _stringio into the main binary, you should ask python-dev or python-3000.
msg71946 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2008-08-25 17:48
On Mon, Aug 25, 2008 at 6:40 AM, Benjamin Peterson <report@bugs.python.org> wrote: > > Benjamin Peterson <musiccomposition@gmail.com> added the comment: > > We could: > > 1. Use _fileio._FileIO directly. > 2. Use os.open. > 3. Initialize the stdio streams before importing site. This seems like > the best option, although I haven't run all the tests yet. > Or you could use _warnings which is already compiled into the binary.
msg71947 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-08-25 17:49
On Mon, Aug 25, 2008 at 12:48 PM, Brett Cannon <report@bugs.python.org> wrote: > > Brett Cannon <brett@python.org> added the comment: > > On Mon, Aug 25, 2008 at 6:40 AM, Benjamin Peterson > <report@bugs.python.org> wrote: >> >> Benjamin Peterson <musiccomposition@gmail.com> added the comment: >> >> We could: >> >> 1. Use _fileio._FileIO directly. >> 2. Use os.open. >> 3. Initialize the stdio streams before importing site. This seems like >> the best option, although I haven't run all the tests yet. >> > > Or you could use _warnings which is already compiled into the binary. How would that help the problem of site using open() when it can't? > > _______________________________________ > Python tracker <report@bugs.python.org> > <http://bugs.python.org/issue3279> > _______________________________________ > -- Cheers, Benjamin Peterson "There's no place like 127.0.0.1."
msg71948 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2008-08-25 17:52
On Mon, Aug 25, 2008 at 10:49 AM, Benjamin Peterson <report@bugs.python.org> wrote: > > Benjamin Peterson <musiccomposition@gmail.com> added the comment: > > On Mon, Aug 25, 2008 at 12:48 PM, Brett Cannon <report@bugs.python.org> wrote: >> >> Brett Cannon <brett@python.org> added the comment: >> >> On Mon, Aug 25, 2008 at 6:40 AM, Benjamin Peterson >> <report@bugs.python.org> wrote: >>> >>> Benjamin Peterson <musiccomposition@gmail.com> added the comment: >>> >>> We could: >>> >>> 1. Use _fileio._FileIO directly. >>> 2. Use os.open. >>> 3. Initialize the stdio streams before importing site. This seems like >>> the best option, although I haven't run all the tests yet. >>> >> >> Or you could use _warnings which is already compiled into the binary. > > How would that help the problem of site using open() when it can't? >> Sorry, replied to the wrong email. It was meant as a reply to Amaury's suggestion of writing out a comment that importing site failed to stderr.
msg72629 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-09-05 21:20
IMO, it's unacceptable to be running Python code before the stdio streams are set up. I believe that moving the site initialization after the setting up the streams isn't as big a problem because the dynlibs are on sys.path before site is run when python is installed. See #586680. I will write to Python-dev.
msg72636 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-09-05 22:14
Here's a patch that builds _bytesio and _stringio right into the binary. I think Windows build files will need to be updated, though.
msg72642 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2008-09-05 22:44
> Windows build files will need to be updated Nothing to do here: they are already built-in, linked into Python30.dll, and listed in PC/config.c But shouldn't the two extension modules be removed from setup.py?
msg72643 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-09-05 22:47
Yes, indeed.
msg72647 - (view) Author: Alexandre Vassalotti (alexandre.vassalotti) * (Python committer) Date: 2008-09-05 23:17
Look good to me, and python-dev accepted the patch. So, go ahead and commit it.
msg72650 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-09-05 23:27
Fixed in r66239.
History
Date User Action Args
2022-04-11 14:56:36 admin set github: 47529
2008-09-05 23:27:32 benjamin.peterson set status: open -> closedresolution: accepted -> fixedmessages: +
2008-09-05 23:17:20 alexandre.vassalotti set assignee: benjamin.petersonresolution: acceptedmessages: +
2008-09-05 22:47:44 benjamin.peterson set files: + make_modules_builtin2.patchmessages: +
2008-09-05 22:44:37 amaury.forgeotdarc set messages: +
2008-09-05 22:14:51 benjamin.peterson set keywords: + needs reviewfiles: + make_modules_builtin.patchmessages: +
2008-09-05 21:20:52 benjamin.peterson set messages: +
2008-09-04 01:09:24 benjamin.peterson set priority: release blocker -> deferred blocker
2008-08-25 17:52:21 brett.cannon set messages: +
2008-08-25 17:49:34 benjamin.peterson set messages: +
2008-08-25 17:48:27 brett.cannon set messages: +
2008-08-25 15:11:47 alexandre.vassalotti set messages: +
2008-08-25 15:02:36 benjamin.peterson set messages: +
2008-08-25 14:54:30 amaury.forgeotdarc set nosy: + alexandre.vassalottimessages: +
2008-08-25 14:37:26 benjamin.peterson set files: + different_order.patchmessages: +
2008-08-25 13:40:56 benjamin.peterson set nosy: + benjamin.petersonmessages: +
2008-08-25 09:32:42 amaury.forgeotdarc set files: + import-site.patchkeywords: + patchmessages: +
2008-08-21 14:51:27 benjamin.peterson set priority: critical -> release blocker
2008-07-04 16:51:41 brett.cannon set nosy: + brett.cannon
2008-07-04 14:34:03 georg.brandl set priority: critical
2008-07-04 11:47:27 amaury.forgeotdarc set nosy: + amaury.forgeotdarcmessages: +
2008-07-04 03:40:26 rupole create