473,785 Members | 2,414 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Clearing a session and reload() problem (with repro error)

Hi,

This seems to be an old question, and I've read back a bit, but rather
than assume the answer is "you can't do that", I'd thought I'd post my
version of the question along with a reproducible error to illustrate
my confusion.

My problem is that I'm using Python inside XSI (a 3D graphics
application). If I want to restart Python, I have to restart XSI. This
is no small amount of time wasted.

The solution would be to somehow unload modules and all references and
allow my imports to rebuild the cache. I suppose it would be great to
clear the python session completely, but the 3D application might have
added something to the session at startup (I doubt this though as I
don't see any imported modules outside the norm).

I've tried to use reload with a very simple algorithm. Simply run
through every imported module, ignoring anything that is "None" or on
the C: drive (all of our python is on a network drive so this hack
works for me for now) and reload() it. I've come to realize that this
isn't near intelligent enough to handle sub-packages.

Before I post the repro, my questions are:
1) Does anyone have a work-flow for my situation that doesn't use
Reload, and doesn't involve restarting the app for every edit/fix

2) Can anyone help point me in the right direction to build a
dependable algorithm to cleanly reload all loaded modules? NOTE: I
don't need to maintain anything in memory (i.e. instances, pointers,
etc.) Everything will be initialized again each time. I'm not asking
for code. Just some ideas or pseudo-code would do nicely.

Here is a "simple" repro...

Package Structure:
---------------------------
inheritRepro
__init__.py
baseLib.py
child
__init__.py
__init__.py:
----------------
import sys, os

def reloadModules() :
"""
Reload all imported modules that are not on the C: drive.
"""
print "Reloading Python Modules..."

# Iterate over all IMPORTED modules
modules = sys.modules
for modName in modules:
mod = modules[modName]

# Skip None types and other itesm we don't care about
if modName == "__main__" or not hasattr(mod,"__ file__"):
continue

# Get the drive and skip anything on the C: drive
drive = os.path.splitdr ive(mod.__file_ _)[0]
if drive != "C:":
reload(mod)
print "Reloaded %s" % mod
baseLib.py:
---------------
class BaseClassA(obje ct):
pass

class BaseClassB(Base ClassA):
def __init__(self):
super(BaseClass B, self).__init__( )
child.__init__. py:
------------------------
import inheritRepro.ba seLib as baseLib

class ChildClass(base Lib.BaseClassB) :
def __init__(self):
super(ChildClas s, self).__init__( )
RUN:
-------
>>import inheritRepro
import inheritRepro.ch ild as child
obj = child.ChildClas s()
print obj
<inheritRepro.c hild.ChildClass object at 0x00B34C70>
>>inheritRepro. reloadModules() # Output omitted, but this worked.
import inheritRepro
import inheritRepro.ch ild as child
obj = child.ChildClas s()
Traceback (most recent call last):
File "<console>" , line 0, in <module>
File "\\nas6tb\PROJE CTS\tech\users\ rafe.sacks\pyth on\inheritRepro
\child\__init__ .py", line 5, in __init__
super(ChildClas s, self).__init__( )
File "\\nas6tb\PROJE CTS\tech\users\ rafe.sacks\pyth on\inheritRepro
\baseLib.py", line 6, in __init__
super(BaseClass B, self).__init__( )
TypeError: super(type, obj): obj must be an instance or subtype of
type
NOTE: this works if I don't use a sub-package for 'child' (child.py
instead). Is it overly simple to assume reloading by file structure
might work?

Right now I'm getting around this by reload()-ing the right package
after running reloadModules() if an error occurs. It's a bit
frustrating that it cost me two days of work before I realized it was
reload() causing this error and not super() or some other unknown-to-
me inheritance/package structure problem. I rebuilt my code module by
module until I noticed, quite by accident, that the thing worked once
and then never again! ....oh well, these are the joys of learning the
hard way.

I know this was a long one. If you made it this far, thanks for
reading,

- Rafe
Sep 8 '08 #1
0 1905

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

Similar topics

13
23339
by: Mimi | last post by:
Hello, I am having trouble using the session vars in PHP 4.3.9 OS: Win XP Prof Web Server IIS (is local and there are no links to other servers from the web pages I work on) Browser: IE 6.0 The problem I am having is that each time I reload the same PHP page, I get
3
5977
by: M Wells | last post by:
Hi All, Just wondering how you go about changing the value of a session cookie via javascript? I have a PHP page that sets a session cookie when it first loads. I'd like to be able to change the value of that session cookie in response to a button click in a form, without resubmitting the page. For some reason, the following doesn't seem to work:
3
15057
by: Brad | last post by:
I'm working with a DataGrid in C#, and the user needs to be able add and remove columns from the DataGrid on the fly, without opening and closing the form. The scenario is this. I have a setup table that allows users to rename columns, resize columns, and select whether or not they want them to be visible or not. While the user is working with a certain set of data, they will want to see certain columns, and in certain situations they...
1
737
by: Werner | last post by:
Hi Patrick! Can you give an example of how to use a frameset inside an aspx-file? When I create a new frameset in Visual Studio.Net it just gives me a htm-File. Or give me a link where I can find one? Thanks Werner P.S. Somehow I did not manage to do a followup in Googles newsgroups.
4
2521
by: N. Demos | last post by:
Hello, I'm learning ASP.NET, and am having a strange problem with some example code from the book I'm using. The code increments and displays the value stored in a session variable when the "Add" button is clicked. In addition, the session variable is reset to zero when the "Empty" button is pressed. The problem is if the value is non-zero and the page is reloaded the value is incremented. It appears as if the "Add" onClick event...
8
1695
by: Tim W. | last post by:
Chaps. We are working with SQL-Server based Sessions in the following environemtn: Win-Server 2K3 incl. IIS, Dot Net Framework 1.1, SQL2K SP3a, German. We are defining a Session-Variable named keyword inside asp.net website. At the end of the Website we are writing this variable again to test if the value still exists to the output-buffer.
9
2217
by: cashdeskmac | last post by:
I have put a string into Session and tried to retrieve it on the next page I visit but the Session appears empty. I have exactly the same spelling for both adding and retrieving the value: Session = "john"; On the next page: txtName.Text = Session;
11
13201
by: Bocah Sableng | last post by:
Hi, I'm new member of this group. I had added new virtual host at my intranet server. The new virtual host configuration on httpd.conf is similar with the old one. At the new virtual host, the session id seems changed every interaction to server (new page or reload). The old one is fine, the session id keeps at the same string. Both are at the same server. I use Apache 2.2.3 (Win32) with PHP 5.2.0.
0
1242
by: Gert Kok | last post by:
I'd like to use 3 types of objects, which have a kind of availability-check as a static object in their parent class. After page reload the initialised member is NULL Is this a PHP 5.2.5 feature or am I missing something? ------------------------------------------------ First page in a session:
0
9483
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
10346
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
10157
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
10096
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
8982
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...
0
6742
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5514
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3658
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2887
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.