Hi, everyone,
I have a bug in a script of several hundred lines of code that I cannot
figure out. I have attempted (unsuccessfully ) to duplicate this problem in
a smaller script that I can post here but have been unsuccessful. As such,
I'm posting code snippets here in the hopes that someone recognizes a very
basic mistake I've made and can straighten me out.
First, the portion of my text file that executes my code:
<quote>
if __name__ == '__main__':
if len(sys.argv) != 2:
print('usage: %s <config_file> ' % sys.argv[0])
sys.exit()
main(sys.argv[1])
</quote>
Here are the first few lines of my 'main' procedure:
<quote>
def main(fileName):
print('DEBUG: begin main procedure')
...
</quote>
And here is the part that is causing problems:
<quote>
# 'keys' is a list of integers returned from dict.keys()
for cycle in keys:
if key in skipList:
print ('skipping %d/%d' % (cycle, cycleMap[cycle]))
continue
try:
print('DEBUG: advancing both simulators to %d' % cycle)
procedureThatCo uldRaiseEOFErro r()
except EOFError:
print('DEBUG: encountered EOFError; breaking loop')
break
print('DEBUG: All cycles processed')
</quote>
Here's what I can't figure out. I'm seeing the following text generated
during this script's execution:
<quote>
DEBUG: advancing both simulators to 20178
DEBUG: encountered EOFError; breaking loop
DEBUG: begin main procedure
</quote>
How is it possible that the call to 'break' is seemingly being replaced with
a call to 'main'?
Thanks!
Scott
--
Remove .nospam from my e-mail address to mail me. 10 1975
Scott Brady Drummonds wrote: I have a bug in a script of several hundred lines of code that I cannot figure out. I have attempted (unsuccessfully ) to duplicate this problem in a smaller script that I can post here but have been unsuccessful. As such, I'm posting code snippets here in the hopes that someone recognizes a very basic mistake I've made and can straighten me out.
Unfortunately you seem to have picked the wrong snippets, which by the way
look made-up. The only error I see
if key in skipList:
...
should probably be
if cycle in skipList:
....
The "most basic" error would be a print statement producing
DEBUG: begin main procedure
sitting in a second place where it doesn't belong and isn't expected.
How is it possible that the call to 'break' is seemingly being replaced with a call to 'main'?
Other than with a buggy C-extension that is not possible.
Peter
"Scott Brady Drummonds" <sc************ **********@inte l.com> wrote in
message news:cf******** **@news01.intel .com... How is it possible that the call to 'break' is seemingly being replaced
with a call to 'main'?
I should also point out that the second time that the program's execution
reaches the 'break' statement in the 'main' procedure, I get the following
cryptic error message:
<quote>
DEBUG: advancing both simulators to 20178
DEBUG: encountered EOFError; breaking loop
XXX lineno: 109, opcode: 0
Traceback (most recent call last):
File "test.py", line 135, in ?
main(sys.argv[1])
File "test.py", line 109, in main
break
SystemError: unknown opcode
</quote>
What's going on here?
Scott
--
Remove .nospam from my e-mail address to mail me.
Scott Brady Drummonds wrote: I should also point out that the second time that the program's execution reaches the 'break' statement in the 'main' procedure, I get the following cryptic error message:
<quote> DEBUG: advancing both simulators to 20178 DEBUG: encountered EOFError; breaking loop XXX lineno: 109, opcode: 0 Traceback (most recent call last): File "test.py", line 135, in ? main(sys.argv[1]) File "test.py", line 109, in main break SystemError: unknown opcode </quote>
What's going on here?
Scrambled .pyc file? Try deleting all .pyc files in the folder
and rerun. (Just a thought.)
Scott Brady Drummonds wrote: Hi, everyone,
I have a bug in a script of several hundred lines of code that I cannot figure out. I have attempted (unsuccessfully ) to duplicate this problem in a smaller script that I can post here but have been unsuccessful. As such, I'm posting code snippets here in the hopes that someone recognizes a very basic mistake I've made and can straighten me out.
First, the portion of my text file that executes my code:
<quote> if __name__ == '__main__': if len(sys.argv) != 2: print('usage: %s <config_file> ' % sys.argv[0]) sys.exit()
main(sys.argv[1]) </quote>
Here are the first few lines of my 'main' procedure: <quote> def main(fileName): print('DEBUG: begin main procedure') ... </quote>
And here is the part that is causing problems: <quote> # 'keys' is a list of integers returned from dict.keys() for cycle in keys: if key in skipList: print ('skipping %d/%d' % (cycle, cycleMap[cycle])) continue try: print('DEBUG: advancing both simulators to %d' % cycle) procedureThatCo uldRaiseEOFErro r() except EOFError: print('DEBUG: encountered EOFError; breaking loop') break print('DEBUG: All cycles processed') </quote>
Here's what I can't figure out. I'm seeing the following text generated during this script's execution: <quote> DEBUG: advancing both simulators to 20178 DEBUG: encountered EOFError; breaking loop DEBUG: begin main procedure </quote>
How is it possible that the call to 'break' is seemingly being replaced with a call to 'main'?
I suspect that the answer is in the context of the for loop. Try
posting a bit more of the surrounding code. (For example, it's not at
all clear how your loop relates to the main() snippet that you posted...)
Actually, I'm wondering why you catch the exception inside the loop, and
then exit the loop. If you wrapped that entire loop in the try/except,
then you wouldn't need to worry about using break -- an exception would
end the loop and *then* get dealt with.
Jeff Shannon
Technician/Programmer
Credit International
"Peter Hansen" <pe***@engcorp. com> wrote in message
news:t8******** ************@po wergate.ca... Scrambled .pyc file? Try deleting all .pyc files in the folder and rerun. (Just a thought.)
Yeah, I tried that before, as well. No such luck.
Scott
"Peter Otten" <__*******@web. de> wrote in message
news:cf******** *****@news.t-online.com... Unfortunately you seem to have picked the wrong snippets, which by the way look made-up. The only error I see
Yeah, that was a typo. I certainly would prefer to post real failing code
as opposed to code snippits, but I needed a way of distilling the importat
parts out of the program. Sorry for doing a bad job of that.
The "most basic" error would be a print statement producing
DEBUG: begin main procedure
sitting in a second place where it doesn't belong and isn't expected.
Right. You've got the idea. There's no reason why the print statement at
the first line of main() should be executed after the break statement. It
doesn't make sense. How is it possible that the call to 'break' is seemingly being replaced with a call to 'main'?
Other than with a buggy C-extension that is not possible.
What is equally more confounding is that I cannot duplicate this error with
a small case I can post here. :( I'm still trying, though...
Scott
--
Remove .nospam from my e-mail address to mail me.
"Jeff Shannon" <je**@ccvcorp.c om> wrote in message
news:10******** *****@corp.supe rnews.com... I suspect that the answer is in the context of the for loop. Try posting a bit more of the surrounding code. (For example, it's not at all clear how your loop relates to the main() snippet that you posted...)
Sorry. I know that it's better to post actual failing code is much better
than snippets for exactly this reason. However, there is so much code that
I believe to be superfluous to this problem that I really wanted to make the
post simpler. To answer your question, the loop that I posted occurred in
the main() loop. That is, calling 'break' inside this loop resulted in a
call to the function that 'break' was called in (which happens to be
main()).
Actually, I'm wondering why you catch the exception inside the loop, and then exit the loop. If you wrapped that entire loop in the try/except, then you wouldn't need to worry about using break -- an exception would end the loop and *then* get dealt with.
After reading your suggestion, I'm wondering why I caught the exception in
the loop as opposed to outside of the loop. I changed the implementation as
you suggested and my program is now working correctly. Of course, something
tells me that I just covered up a bug as opposed to removing it.
Scott
--
Remove .nospam from my e-mail address to mail me.
Scott Brady Drummonds wrote: After reading your suggestion, I'm wondering why I caught the exception in the loop as opposed to outside of the loop. I changed the implementation as you suggested and my program is now working correctly. Of course, something tells me that I just covered up a bug as opposed to removing it.
Probably you're right about that. Better to use your original code to
figure out what's going wrong, than to proceed with changed code that
might not fix the problem. Once you've found the bug, *then* you can
switch to catching the exception outside of the loop. ;)
If your main() function has so much code, then try breaking that down
into several smaller functions. It's almost certain that you can break
a large function into several logical "sections"; if you make each of
those sections into a separate function, it'll probably be easier to
isolate the specific problem.
As an example, you could probably isolate that for loop within a
subfunction --
def ProcessCycleMap (cycleMap, keys, skipList):
for cycle in keys:
....
You may also want to go through your code and verify that you don't have
anyplace that mixes tabs and spaces, which can lead to invisibly
mismatched indentation. It may be that the compiler sees your code
structure a bit differently than you do... (Best procedure here is to
simply run tabnanny.py over your code.)
Jeff Shannon
Technician/Programmer
Credit International
"Scott Brady Drummonds" <sc************ **********@inte l.com> writes:
[...] DEBUG: advancing both simulators to 20178
[...]
Is this a threaded program?
John This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Vinny |
last post by:
Can anyone help me with this strange problem please?
I have a stored procedure, with a parameter defined as a
uniqueidentifier. The procedure does a select with a number of joins,
and filters within the Where clause using this parameter.
(@orderHeader_id uniqueidentifier)
SELECT *
|
by: mas |
last post by:
I have a Stored Procedure (SP) that creates the data required for a
report that I show on a web page. The SP does all the work and just
returns back a results set that I dump in an ASP.NET DataGrid. The SP
takes a product area and a start and end date as parameters.
Here are the basics of the SP.
1. Create temp table to store report...
|
by: Raquel |
last post by:
This is a stored procedure that resides on Mainframe and gets executed on
the client by connecting to the mainframe through DB2 connect. It was
executing fine till yesterday when I executed a table change and
successfully Rebound the package associated with the stored procedure.
Since then, it is giving a strange problem. When the client...
|
by: Bill Borg |
last post by:
Hello,
I call a function recursively to find an item that exists *anywhere* down
the chain. Let's say I find it five layers deep. Now I've got what I need and
want to break out of that whole stack and continue execution at the point of
the initial call. Is that possible?
Thanks,
Bill
|
by: Frank van Vugt |
last post by:
Hi,
If during a transaction a number of deferred triggers are fired, what will be
their execution order upon the commit?
Will they be executed in order of firing or alfabetically or something
entirely different? The docs only mention regular triggers being executed
alfabetically.
| |
by: TheRealPawn |
last post by:
I'm trying to get the execution plan for a single stored procedure
from Profiler. Now, I've isolated the procedure but I get all
execution plans. Any ideas on how to connect the SPIDs so that I only
get the execution plan for the procedure I'm watching and not the
whole of the server?
|
by: sqlgirl |
last post by:
Hi,
We are trying to solve a real puzzle. We have a stored procedure that
exhibits *drastically* different execution times depending on how its
executed.
When run from QA, it can take as little as 3 seconds. When it is
called from an Excel vba application, it can take up to 180 seconds.
Although, at other times, it can take as little as...
|
by: Yansky |
last post by:
Hi, I've looked through the tutorial on w3cschools.com, but I'm still
uncertain as to the difference between using break and using return.
If I have a simple "for" loop that I want to stop if a condition is
met, should I use break or return to stop the loop?
e.g. is something like this ok? Would using return do the same thing?
var dow =...
|
by: smileprince00 |
last post by:
what is meant by break point in the sql server studio.. what is the purpose of it..let me know clearly........................
and one more thing is i am hearing a word regularly while studying about sql server and ms visual stdio.. i.e INTELLISENSE can you explain me clearly what it is and why it is used .
hoping for a better and...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |