472,358 Members | 2,070 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,358 software developers and data experts.

eval() of empty string hangs

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.
Jul 18 '05 #1
6 3260
Chris Connett wrote:

[...]
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. [...] 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.


As an alternative, and not requiring that you special case
anything, does it work if you simply append '\n' to the
string to be eval'ed in all cases?

-Peter
Jul 18 '05 #2
Chris Connett wrote:
self.logger.debug( 'before second parse' )
self.references = eval( file(
self.temp_path + '/referenceOutput' ).read() )

You could modify the above to

self.logger.debug( 'before read' )
data = file(...).read()
self.logger.debug( 'before second parse' )
self.references = eval(data)

to verify that eval() is indeed the culprit.

Peter

Jul 18 '05 #3
Sorry, I overlooked the earlier eval().

Peter
Jul 18 '05 #4
Peter Hansen wrote:

As an alternative, and not requiring that you special case
anything, does it work if you simply append '\n' to the
string to be eval'ed in all cases?


I did try a number of ways of massaging the input string, though far
from exhaustive; I tried adding the single newline - it didn't help.

I did however localize the problem more tightly. It does not seem to be
eval that's hanging, but raise-ing is not working. When I tried my
original plan of special casing '', I added a check for equality, then
manually raised a SyntaxError. This exhibited the same behavior. I
then tried unconditionally raising SyntaxError, same result. Is it
possible that the exception is propagating up the wrong stack? This is
a separate thread, could it be on the main thread somehow? The creating
thread has ended by the time this exception is due to be raised. There
are numerous try-excepts to catch this, all should log at least some
message, but the log shows nothing.

Jul 18 '05 #5
Chris Connett wrote:
Is it
possible that the exception is propagating up the wrong stack? This is
a separate thread, could it be on the main thread somehow? The creating
thread has ended by the time this exception is due to be raised.


This doesn't make sense to me. What do you mean by 'creating thread'?
If it's what I think you mean, then either it's not really the
creating thread, or it hasn't really ended yet... after all, how
could a thread that has ended cause an exception to occur?
Jul 18 '05 #6
Peter Hansen wrote:
Chris Connett wrote:
Is it possible that the exception is propagating up the wrong stack?
This is a separate thread, could it be on the main thread somehow?
The creating thread has ended by the time this exception is due to be
raised.

This doesn't make sense to me. What do you mean by 'creating thread'?
If it's what I think you mean, then either it's not really the
creating thread, or it hasn't really ended yet... after all, how
could a thread that has ended cause an exception to occur?


I didn't mean to confuse, just throwing some ideas out, sorry.

Here's the big picture:
A function is called, which creates a Submission object, and then calls
a sequence of methods on it. Since this is a normal everyday function,
the user must wait for it to finish. So after some basic integrity
checks, it creates a new thread to do the major processing, which could
take a significant amount of time. Once that thread is created and
started, the function the user called returns, and the user goes on
their merry way. The thread from which the user originally called the
first function should end shortly after that, but as always with
threading, no guarantees.

....

Well, I've found the problem. My own oversight, a NameError in the top
level except block, I forgot to qualify the name of the Exception being
caught. I should have used pychecker, I have no excuse not to have,
it's installed. Sorry to have wasted the group's time, but I have
learned from this greatly. Nothing like complete embarrassment in front
of one's peers to make a lesson stick. ;)

Jul 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: HikksNotAtHome | last post by:
This is a very simplified example of an Intranet application. But, is there an easier (or more efficient) way of getting the decimal equivalent of a fraction? The actual function gets the select...
5
by: bg | last post by:
Hi! How do I check if "date" exists before using that code? I've built a RSSreader and sometimes there's a date in it and sometimes not. How can I check if it exists to avoid crash...
1
by: Chris | last post by:
Hey Okay using DataBinder.Eval in a repeater. My question is this - if the value is empy, eg the myDownloadFile is empty, how can i display different output than if it was populated. #...
18
by: Joe Fallon | last post by:
I have some complex logic which is fairly simply to build up into a string. I needed a way to Eval this string and return a Boolean result. This code works fine to achieve that goal. My...
11
by: eddy de boer | last post by:
Hello, in my aspx page I have the followong code: <asp:Repeater id="Repeater1" runat="server"> <ItemTemplate> .... <%# Server.HtmlDecode((string)DataBinder.Eval(Container.DataItem,"tekst"))...
15
by: manstey | last post by:
Hi, I have a text file called a.txt: # comments I read it using this:
2
by: Florian Loitsch | last post by:
hi, What should be the output of the following code-snippet? === var x = "global"; function f() { var x = 0; eval("function x() { return false; }"); delete x; alert(x); }
3
by: Kevin Blount | last post by:
I'm putting a radG:GridTemplateColumn together (which is probably irelevant), and within it I'm using a Label, as so: <asp:Label ID="defaultDescription" runat="server" Text='<%#...
3
by: sphengle | last post by:
It’s Friday afternoon and I’m being driven mad by a simple .NET problem. Can you help? I’m binding in a repeater where I know there’s a possibility that the value for a field in a dataset could...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it so the python app could use a http request to get...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
0
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.