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) *  |
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) *  |
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) *  |
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) *  |
Date: 2008-08-25 14:37 |
Here's my patch for the problem. |
|
|
msg71931 - (view) |
Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) *  |
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) *  |
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) *  |
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) *  |
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) *  |
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) *  |
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) *  |
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) *  |
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) *  |
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) *  |
Date: 2008-09-05 22:47 |
Yes, indeed. |
|
|
msg72647 - (view) |
Author: Alexandre Vassalotti (alexandre.vassalotti) *  |
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) *  |
Date: 2008-09-05 23:27 |
Fixed in r66239. |
|
|