Jump to content

hou.session not removing variable?


peliosis

Recommended Posts

Is it correct that if I run

hou.setSessionModuleSource('a = 1')
hou.setSessionModuleSource('b = 1')

"a" should be deleted.

The source editor window shows only b = 1, but in hou.session both variables are kept???

dir(hou.session)

gives a AND b, so the first variable is not deleted?

It's not the matter of life and death but supposed "a" can possibly be a huuuge array it can clutter memory.

Link to comment
Share on other sites

This is what I would expect to happen given how Python modules tend to work.

The session module is just another module and the source is what defines it. Every time you change something through either the dialog or by setting it using Python, you are essentially reloading that module, which creates any new data members and refreshes any that are changed. Ones that were removed or renamed will still exist until the session is over or they are specifically deleted.

This is a regular Python behavior, not specific to Houdini.

An example is as follows:

Define a new module, mymodule.py that contains a definition for a function, foo() and a constant x=5. If you import that module into a standard Python session you then can access foo and x. Now, in that file, delete the definitions for the function and constant and define a new function, bar() and a constant y=-1. If you reload(mymodule) in your session and do a dir(mymodule) you will now see foo, bar, x and y even though you removed the original function and constant in the source. To remove the 'leftover' members you could do del(mymodule.foo) and del(mymodule.x). If you start a new session and import mymodule you will only get bar and y.

Edited by graham
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...