eval() of empty string hangs

Chris Connett chrisccc_3k at yahoo.com
Wed Jul 28 09:48:42 EDT 2004


I have an interesting problem with eval().  

---Background Info---
The program I'm working on launches a separate process with a popen to
do some highly specialized processing of input, then this process
leaves resultant data structured in files, in python syntax, at a
known absolute path, which is then read in, eval()'ed, and processed
further.  It works fine when there are no errors in processing by this
external program, but when there are errors, it leaves an empty file. 
When I .read() this file, I get an empty string, as expected.

---The interesting part---
When I eval the empty string in this context, instead of a
SyntaxError, like I expect and am prepared to handle, the program
hangs.  If I run the example in a standard interactive shell, it
raises a SyntaxError, like I expect.  Only here does it hang.

---More info---
This is Python 2.3.4, built from source, on Red Hat Enterprise Server
8.  The code in question is started in a thread from a Zope external
method.  Remember it works fine when there is an actual data structure
representation in the string, only when there should be a syntax error
does it hang (I've check by sticking in some other invalid evals, they
hang too), so it doesn't seem to be a Zope security issue (it's an
external method anyhow, so there shouldn't be any restrictions).  It
is started in a new thread, so there is the possibility of the
exception silently crashing the thread, but I have a try-except to
catch everything around the offending code, and log some message, but
that message never comes either.

---Code---
def parseProofResults(self):
    """Parse the declarationOutput and referenceOutput files for PVS
    entities and references.
    """

    try:
        self.logger.debug( 'before first parse' )
        self.declarations = file(
            self.temp_path + '/declarationOutput' )
        self.logger.debug( 'opened file' )
        self.declarations = self.declarations.read()
        self.logger.debug( 'read:\n' + repr(self.declarations) )
        self.logger.debug( self.declarations == '' )
        self.declarations = eval( self.declarations )
        self.logger.debug( 'before second parse' )
        self.references = eval( file(
            self.temp_path + '/referenceOutput' ).read() )
        self.logger.debug( 'parsed' )
    except SyntaxError, e:
        raise ProofError, \
            'Error parsing prover output, caused by unproven TCCs.'
-Where it's called from
# Stage 2
    try:
        candidate.parseProofResults()
    except ProofError, e:
        candidate.logger.log( submission.FAILURE, e )
        return
    except:
        candidate.logger.error( 'Some error.' )
        return

    candidate.logger.log( submission.STATUS, 'Typechecking results
parsed.' )

---Log file excerpt---
At 2004-07-28 08:53:06,265, DEBUG for submission 344
        before first parse
At 2004-07-28 08:53:06,266, DEBUG for submission 344
        opened file
At 2004-07-28 08:53:06,266, DEBUG for submission 344
        read:
''
At 2004-07-28 08:53:06,266, DEBUG for submission 344
        True

---Summary---
I should be able to work around this, just check a special case for
the empty string, since that seems to be the only actual case that
arises, but this problem is a real puzzle to me, and I wanted to throw
it out there to see what others think.



More information about the Python-list mailing list