473,692 Members | 2,445 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reload after an exception, not possible ?

hello,

I've a graphical application (wxPython),
where the code in the main GUI loop is given below.
1 JAL_Loaded = False
2 while len(App_Running ) 0:
3 if JALsPy_globals. State == SS_Run:
4 try:
5 if JAL_Loaded:
6 reload ( JAL_simulation_ file )
7 else:
8 JAL_Loaded = True
9 import JAL_simulation_ file
10 except JALsPy_globals. Reload_Exceptio n:
11 JALsPy_globals. State = SS_Halt
The first time the while loop is entered,
JAL_Loaded is False (line 1),
and when I press some button,
the code will enter at line 8,
importing a module, that has executable code with an infinite loop.

To exit this infinite loop, an exception is generated (by a button press),
and program comes back in the above while-loop line (10,11,2).

So far so good.

Then I change the code in the imported file,
and when I start the engine again,
the flag JAL_Loaded is True, so I don't import,
but I reload the file.

Now I get the next exception
UnboundLocalErr or: local variable 'JAL_simulation _file' referenced before assignment

So obviously I can't reload but have to do an import again
(which makes the code much simpler ;-)
but I don't understand why the reload raises an exception ????

please enlighten me,
thanks,
Stef Mientki

Jul 31 '07 #1
3 1550
Stef Mientki wrote:
hello,

I've a graphical application (wxPython),
where the code in the main GUI loop is given below.
1 JAL_Loaded = False
2 while len(App_Running ) 0:
3 if JALsPy_globals. State == SS_Run:
4 try:
5 if JAL_Loaded:
6 reload ( JAL_simulation_ file )
7 else:
8 JAL_Loaded = True
9 import JAL_simulation_ file
10 except JALsPy_globals. Reload_Exceptio n:
11 JALsPy_globals. State = SS_Halt
The first time the while loop is entered,
JAL_Loaded is False (line 1),
and when I press some button,
the code will enter at line 8,
importing a module, that has executable code with an infinite loop.

To exit this infinite loop, an exception is generated (by a button press),
and program comes back in the above while-loop line (10,11,2).

So far so good.

Then I change the code in the imported file,
and when I start the engine again,
the flag JAL_Loaded is True, so I don't import,
but I reload the file.

Now I get the next exception
UnboundLocalErr or: local variable 'JAL_simulation _file' referenced before assignment

So obviously I can't reload but have to do an import again
(which makes the code much simpler ;-)
but I don't understand why the reload raises an exception ????
You have an assignment to JAL_simulation_ file elsewhere inside the same
function, later in the code. This means that Python will assume that it
is local to the function, but the import statement will affect the
module namespace rather than the function namespace.

In other words, your code is roughly equivalent to what follows, with
the added complexity that the illegal reference isn't triggered until
the second iteration of a loop.
>>def f():
.... print os
.... import os
.... os = "Something"
....
>>f()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 2, in f
UnboundLocalErr or: local variable 'os' referenced before assignment
>>>
The solution? Don't assign to JAL_simulation_ file, and the function will
use the local instead.

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------

Aug 1 '07 #2
Steve Holden wrote:
[...]
The solution? Don't assign to JAL_simulation_ file, and the function will
use the local instead.
Sorry, that last "local" should have been "global".

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------

Aug 1 '07 #3
Steve Holden wrote:
Stef Mientki wrote:
>hello,

I've a graphical application (wxPython),
where the code in the main GUI loop is given below.
1 JAL_Loaded = False
2 while len(App_Running ) 0:
3 if JALsPy_globals. State == SS_Run:
4 try:
5 if JAL_Loaded:
6 reload ( JAL_simulation_ file )
7 else:
8 JAL_Loaded = True
9 import JAL_simulation_ file
10 except JALsPy_globals. Reload_Exceptio n:
11 JALsPy_globals. State = SS_Halt
The first time the while loop is entered,
JAL_Loaded is False (line 1),
and when I press some button,
the code will enter at line 8,
importing a module, that has executable code with an infinite loop.

To exit this infinite loop, an exception is generated (by a button
press),
and program comes back in the above while-loop line (10,11,2).

So far so good.

Then I change the code in the imported file,
and when I start the engine again,
the flag JAL_Loaded is True, so I don't import,
but I reload the file.

Now I get the next exception
UnboundLocalErr or: local variable 'JAL_simulation _file' referenced
before assignment

So obviously I can't reload but have to do an import again
(which makes the code much simpler ;-)
but I don't understand why the reload raises an exception ????
You have an assignment to JAL_simulation_ file elsewhere inside the same
function,
No these are the only 2 uses of "JAL_simulation _file" in the whole project.

later in the code. This means that Python will assume that it
is local to the function, but the import statement will affect the
module namespace rather than the function namespace.

In other words, your code is roughly equivalent to what follows, with
the added complexity that the illegal reference isn't triggered until
the second iteration of a loop.
>>def f():
... print os
... import os
... os = "Something"
...
>>f()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 2, in f
UnboundLocalErr or: local variable 'os' referenced before assignment
>>>

The solution? Don't assign to JAL_simulation_ file, and the function will
use the local instead.
The solution is much simpler, but I don't understand why the "import",
which really reloads the changed code in JAL_simulation_ file,
works the second time :-(

2 while len(App_Running ) 0:
3 if JALsPy_globals. State == SS_Run:
4 try:
9 import JAL_simulation_ file
10 except JALsPy_globals. Reload_Exceptio n:
11 JALsPy_globals. State = SS_Halt

cheers,
Stef Mientki
Aug 1 '07 #4

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

Similar topics

66
3885
by: Ellinghaus, Lance | last post by:
> > Other surprises: Deprecating reload() >Reload doesn't work the way most people think >it does: if you've got any references to the old module, >they stay around. They aren't replaced. >It was a good idea, but the implementation simply >doesn't do what the idea promises. I agree that it does not really work as most people think it does, but how
1
2142
by: Emmanuel | last post by:
Hi, I use a 'reload all' feature in my app, that allow to reload every module. I first try this version : import sys def Reload():
1
2883
by: Cooper | last post by:
Hello, is possible to disable the reload (or update, for ie) of the a web page? If yes, what i do? Otherwise if isn't possible, what i do for to set the default value of a form when a user do a reload of update of the web page? Thank you, Cooper.
0
1852
by: fhiemstra0507 | last post by:
Hi I have a listbox that I want to update when the an item is updated/added. Now the listbox is attached to a query. Now I tried to just reload the query by modifying the forms loadDataSet and filldataset subroutines but when I do that the table values do not mesh which the lstbox anymore. As well, I have looked at the data adapters select statement to try and update it but to no avail. Any suggestions?
18
10138
by: Alan Z. Scharf | last post by:
1. I have a chain of six asynch callbacks initiated by a button, and want the page to refresh at the end of each callback to display A. Results of a SQLServer query showing cumulative running time, and B. A progress bar. 2. I have this working with a refresh timer: <META http-equiv="refresh" content="5">
2
2824
by: gen_tricomi | last post by:
Python 2.4.2 (#67, Sep 28 2005, 12:41:11) on win32 Type "copyright", "credits" or "license()" for more information. **************************************************************** Personal firewall software may warn about the connection IDLE makes to its subprocess using this computer's internal loopback interface. This connection is not visible on any external interface and no data is sent to or received from the Internet....
14
3442
by: fdu.xiaojf | last post by:
Hi, I have a program which will continue to run for several days. When it is running, I can't do anything except waiting because it takes over most of the CUP time. Is it possible that the program can save all running data to a file when I want it to stop, and can reload the data and continue to run from where it stops when the computer is free ?
1
4023
by: nkoriginal | last post by:
Hello Again: I've a problem with my forms. I woking with an intranet, and the pages in that intranet, has a reload page, every 10 minutos. So my problems star, when any user stay in my forms for more longe than 10 minutes, and the page reload, the user lose all data in that forms, if he not did submit. I want to keep the user form data, after reload. Is that possible? so, en litle words, if the user stay in my forms and he filled...
2
1901
by: Max | last post by:
Is it possible to reload a web page on user browser when an event occurs at server side? For example when user A places an order, user B should be notified of that and should see that order on his page. I 'd like to avoid to reload B page every nnn seconds. Or at least, I'd like to check if something interesting has changed on server and only in that case to reload the page. Any suggestion? Thanks Max
0
8610
marktang
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8544
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9090
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, 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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8968
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8810
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7633
agi2029
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6462
isladogs
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4325
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
1961
bsmnconsultancy
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.