473,396 Members | 1,773 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 3443
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.