[ python-Bugs-1771260 ] Errors in site.py not reported properly

SourceForge.net noreply at sourceforge.net
Fri Aug 10 20:19:06 CEST 2007


Bugs item #1771260, was opened at 2007-08-09 15:37
Message generated for change (Comment added) made by rhamphoryncus
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1771260&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: Python 3000
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Adam Olsen (rhamphoryncus)
Assigned to: Nobody/Anonymous (nobody)
Summary: Errors in site.py not reported properly

Initial Comment:
(Ignore the p3yk dir name.  This has been updated to the py3k branch.)

rhamph at factor:~/src/python-p3yk/build$ make
object  : 
type    : TypeError
refcount: 4
address : 0x8239f0c
lost sys.stderr
make: *** [sharedmods] Error 1

The root cause is that (due to some local modifications) site.py failed to load and gave an error.  This can be easily duplicated by opening up Lib/site.py:main and putting 1/0 on the first line.

However, the ZeroDivisionError that should cause never gets printed.  Python/pythonrun.c:initsite attempts to retrieve sys.stderr, which fails because site.py never got a chance to install it (!), then passes the NULL file object pointer to PyFile_WriteString, which turns that into a new exception (replacing the old one).  initsite ignores the return value indicating the exception, instead clearing it, and the interpreter continues to load, no one the wiser.

Several other exceptions may happen and get squashed, I'm not sure.

Eventually, Python/sysmodule.c:sys_excepthook calls Python/pythonrun.c:PyErr_Display, which attempts to retrieve sys.stderr, and failing that calls _PyObject_Dump() on the exception (explaining the weird message).  Oddly, there's a *second* if statement, which then prints the "lost sys.stderr" line.


Possible remedies:
1.  PyErr_Display's dump message is not very clear.
2.  initsite should go directly to stderr if it can't retrieve sys.stderr.  Alternatively, since site.py is now more important, it could be changed into a fatal error.  Yet another option is to explicitly check for sys.stderr even on success and make that alone into a fatal error.
3.  The error printing APIs could be modified to internalize the stderr retrieval.  Upon failure they could print a brief "stderr unavailable; original exception was ..." message.

----------------------------------------------------------------------

>Comment By: Adam Olsen (rhamphoryncus)
Date: 2007-08-10 12:19

Message:
Logged In: YES 
user_id=12364
Originator: YES

Following up on the possible remedies, I'm thinking PySys_WriteStderr
could be extended to take file object as the first argument, and if null it
writes to low-level stderr instead.  That way the callers can add the
message about "lost sys.stderr" themselves, rather than it being
interspersed in their output.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1771260&group_id=5470


More information about the Python-bugs-list mailing list