persistencemanager with ipython

Running wxPython 2.9.4, iPython 0.31.1, python 2.7.3, windows 8

The first time I run my script which uses PersistenceManager, within a given iPython session, wxPython (I think correctly) puts Persistence_Options in C:\Users\Lou\AppData\Roaming<scriptname>\ .

But when I run the script a subsequent time in the same iPython session, it seems to be putting Persistence_Options in C:\Users\Lou\AppData\Roaming\ .

If I exit iPython and start again, C:…<scriptname>\ is used again.

I suspect that some state is maintained within the iPython session, which is preventing PersistenceManager from finding the right directory on the nth running where n>1.

I tried PersistenceManager.Free() when program exits, but that didn’t seem to help.

Any suggestions?

Hi Lou,

Running wxPython 2.9.4, iPython 0.31.1, python 2.7.3, windows 8

The first time I run my script which uses PersistenceManager, within a given
iPython session, wxPython (I think correctly) puts Persistence_Options in
C:\Users\Lou\AppData\Roaming\<scriptname>\ .

But when I run the script a subsequent time in the same iPython session, it
seems to be putting Persistence_Options in C:\Users\Lou\AppData\Roaming\ .

If I exit iPython and start again, C:\...\<scriptname>\ is used again.

I suspect that some state is maintained within the iPython session, which is
preventing PersistenceManager from finding the right directory on the nth
running where n>1.

I tried PersistenceManager.Free() when program exits, but that didn't seem
to help.

Any suggestions?

I am not sure what is going on, I never used IPython. However, what
PersistentManager only does is to fetch the user data directory via:

wx.StandardPaths.Get().GetUserDataDir()

and then join that directory with the "Persistence_Options" file name.
What I found out is that, if you run the above line in a Python
prompt, you get the following (for me):

D:\MyProjects\Phaser\RC04\0.4.9>python
Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit
(AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

import wx
app = wx.App(0)
wx.StandardPaths.Get().GetUserDataDir()

u'C:\\Users\\aga108\\AppData\\Roaming\\python'

While if I run it in PythonWin I get this:

wx.StandardPaths.Get().GetUserDataDir()

u'C:\\Users\\aga108\\AppData\\Roaming\\Pythonwin'

So it seems to me that GetUserDataDir() adds the current editor/python
session name to the actual data dir (which is what the documentation
says it should do). It may or may not be related to your problem
directly, but if I were you I would run your script from the command
line and not in a IPython session. Of course I will welcome any
improvements to the way PersistentManager handles where the data is
stored...

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."

# ------------------------------------------------------------- #
def ask_mailing_list_support(email):

    if mention_platform_and_version() and include_sample_app():
        send_message(email)
    else:
        install_malware()
        erase_hard_drives()
# ------------------------------------------------------------- #

···

On 12 December 2012 21:30, Lou King wrote:

Maybe use SetPersistenceFile instead, I do this in my app:

persFile = os.path.join(wx.GetApp().persistanceLoc,
                                        self.view.GetName())
self._persistMgr.SetPersistenceFile(persFile)

Which on my pc translates to something like:

u'C:\\Users\\username\\AppData\\Roaming\\appname\\persistance\\pfileforthisview'

Werner

···

On 14/12/2012 09:05, Andrea Gavana wrote:

Hi Lou,

On 12 December 2012 21:30, Lou King wrote:

Running wxPython 2.9.4, iPython 0.31.1, python 2.7.3, windows 8

The first time I run my script which uses PersistenceManager, within a given
iPython session, wxPython (I think correctly) puts Persistence_Options in
C:\Users\Lou\AppData\Roaming\<scriptname>\ .

But when I run the script a subsequent time in the same iPython session, it
seems to be putting Persistence_Options in C:\Users\Lou\AppData\Roaming\ .

If I exit iPython and start again, C:\...\<scriptname>\ is used again.

I suspect that some state is maintained within the iPython session, which is
preventing PersistenceManager from finding the right directory on the nth
running where n>1.

I tried PersistenceManager.Free() when program exits, but that didn't seem
to help.

Any suggestions?

I am not sure what is going on, I never used IPython. However, what
PersistentManager only does is to fetch the user data directory via:

wx.StandardPaths.Get().GetUserDataDir()

and then join that directory with the "Persistence_Options" file name.
What I found out is that, if you run the above line in a Python
prompt, you get the following (for me):

D:\MyProjects\Phaser\RC04\0.4.9>python
Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit
(AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

import wx
app = wx.App(0)
wx.StandardPaths.Get().GetUserDataDir()

u'C:\\Users\\aga108\\AppData\\Roaming\\python'
While if I run it in PythonWin I get this:

wx.StandardPaths.Get().GetUserDataDir()

u'C:\\Users\\aga108\\AppData\\Roaming\\Pythonwin'

So it seems to me that GetUserDataDir() adds the current editor/python
session name to the actual data dir (which is what the documentation
says it should do). It may or may not be related to your problem
directly, but if I were you I would run your script from the command
line and not in a IPython session. Of course I will welcome any
improvements to the way PersistentManager handles where the data is
stored...

Thanks. I will look at these and report back. Right now, for me, this is more of an annoyance than a real problem. I’m using iPython to debug my script, which will end up packaged in an egg or through py2exe. I think a real user of the script will not have this problem. But again it annoys me because my persistence file ends up in three places (the additional one being …/-script/ when run from the egg .exe). Seems like the SetPersistenceFile is the way to go, unless wx.GetApp().persistenceLoc gives different values on 1st versus nth running within iPython.

There are some other known state related issues when using iPython, as it is just a python script itself. I’m looking for ways to work around these which don’t impact the final product.

···

On Friday, December 14, 2012 3:40:26 AM UTC-5, werner wrote:

On 14/12/2012 09:05, Andrea Gavana wrote:

Hi Lou,

On 12 December 2012 21:30, Lou King wrote:

Running wxPython 2.9.4, iPython 0.31.1, python 2.7.3, windows 8

The first time I run my script which uses PersistenceManager, within a given

iPython session, wxPython (I think correctly) puts Persistence_Options in

C:\Users\Lou\AppData\Roaming<scriptname>\ .

But when I run the script a subsequent time in the same iPython session, it

seems to be putting Persistence_Options in C:\Users\Lou\AppData\Roaming\ .

If I exit iPython and start again, C:.…<scriptname>\ is used again.

I suspect that some state is maintained within the iPython session, which is

preventing PersistenceManager from finding the right directory on the nth

running where n>1.

I tried PersistenceManager.Free() when program exits, but that didn’t seem

to help.

Any suggestions?

I am not sure what is going on, I never used IPython. However, what

PersistentManager only does is to fetch the user data directory via:

wx.StandardPaths.Get().GetUserDataDir()

and then join that directory with the “Persistence_Options” file name.

What I found out is that, if you run the above line in a Python

prompt, you get the following (for me):

D:\MyProjects\Phaser\RC04\0.4.9>python

Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit

(AMD64)] on win32

Type “help”, “copyright”, “credits” or “license” for more information.

import wx

app = wx.App(0)

wx.StandardPaths.Get().GetUserDataDir()

u’C:\Users\aga108\AppData\Roaming\python’

While if I run it in PythonWin I get this:

wx.StandardPaths.Get().GetUserDataDir()

u’C:\Users\aga108\AppData\Roaming\Pythonwin’

So it seems to me that GetUserDataDir() adds the current editor/python

session name to the actual data dir (which is what the documentation

says it should do). It may or may not be related to your problem

directly, but if I were you I would run your script from the command

line and not in a IPython session. Of course I will welcome any

improvements to the way PersistentManager handles where the data is

stored…

Maybe use SetPersistenceFile instead, I do this in my app:

persFile = os.path.join(wx.GetApp().persistanceLoc,

                                    self.view.GetName())

self._persistMgr.SetPersistenceFile(persFile)

Which on my pc translates to something like:

u’C:\Users\username\AppData\Roaming\appname\persistance\pfileforthisview’

Werner

Thanks. I will look at these and report back. Right now, for me, this is more of an annoyance than a real problem. I'm using iPython to debug my script,

Can you explain why you use iPython to debug? What does this give in addition to e.g. debugging with WingIDE or Boa debugger or using the wxPython.WIT.

which will end up packaged in an egg or through py2exe. I think a real user of the script will not have this problem. But again it annoys me because my persistence file ends up in three places (the additional one being .../<scriptname>-script/ when run from the egg .exe). Seems like the SetPersistenceFile is the way to go, unless wx.GetApp().persistenceLoc

Shouldn't as you control it, e.g. I do:
         sp = wx.StandardPaths.Get()
         self.configLoc = sp.GetUserConfigDir()
         self.configLoc = os.path.join(self.configLoc, self.appName)
         # win: C:\Users\userid\AppData\Roaming\yourAppName
         # nix: \home\userid\yourAppName

         if not os.path.exists(self.configLoc):
             os.mkdir(self.configLoc)

         self.persistanceLoc = os.path.join(self.configLoc, "Persistance")
         if not os.path.exists(self.persistanceLoc):
             os.mkdir(self.persistanceLoc)

The above uses the appName I decide and does not depend on whatever "GetUserDataDir" does to figure out the appName.

Werner

···

On 14/12/2012 12:55, Lou King wrote:

Seems wx…GetUserDataDir() changes after the first execution. I’ve set persistenceLoc almost like Werner suggested, leaving out the /Persistence folder.

Werner, is there any reason you put the persistence for different windows into different files?

···

On Fri, Dec 14, 2012 at 7:12 AM, Werner werner.bruhin@sfr.fr wrote:

On 14/12/2012 12:55, Lou King wrote:

Thanks. I will look at these and report back. Right now, for me, this is more of an annoyance than a real problem. I’m using iPython to debug my script,

Can you explain why you use iPython to debug? What does this give in addition to e.g. debugging with WingIDE or Boa debugger or using the wxPython.WIT.

which will end up packaged in an egg or through py2exe. I think a real user of the script will not have this problem. But again it annoys me because my persistence file ends up in three places (the additional one being …/-script/ when run from the egg .exe). Seems like the SetPersistenceFile is the way to go, unless wx.GetApp().persistenceLoc

Shouldn’t as you control it, e.g. I do:

    sp = wx.StandardPaths.Get()

    self.configLoc = sp.GetUserConfigDir()

    self.configLoc = os.path.join(self.configLoc, self.appName)

    # win: C:\Users\userid\AppData\Roaming\yourAppName

    # nix: \home\userid\yourAppName



    if not os.path.exists(self.configLoc):

        os.mkdir(self.configLoc)



    self.persistanceLoc = os.path.join(self.configLoc, "Persistance")

    if not os.path.exists(self.persistanceLoc):

        os.mkdir(self.persistanceLoc)

The above uses the appName I decide and does not depend on whatever “GetUserDataDir” does to figure out the appName.

Werner

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

Hi Lou,

Seems wx...GetUserDataDir() changes after the first execution. I've set persistenceLoc almost like Werner suggested, leaving out the /Persistence folder.

I have a folder to easier find the other configuration files.

Werner, is there any reason you put the persistence for different windows into different files?

I have one for the app and one per dialog. Just easier to manage if one changes something and wants to remove just the one for a certain dialog.

Werner

···

On 14/12/2012 16:44, Lou King wrote:

I am not sure what is going on, I never used IPython. However, what
PersistentManager only does is to fetch the user data directory via:

wx.StandardPaths.Get().GetUserDataDir()

and then join that directory with the "Persistence_Options" file name.
What I found out is that, if you run the above line in a Python
prompt, you get the following (for me):

D:\MyProjects\Phaser\RC04\0.4.9>python
Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit
(AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

import wx
app = wx.App(0)
wx.StandardPaths.Get().GetUserDataDir()

u'C:\\Users\\aga108\\AppData\\Roaming\\python'

While if I run it in PythonWin I get this:

wx.StandardPaths.Get().GetUserDataDir()

u'C:\\Users\\aga108\\AppData\\Roaming\\Pythonwin'

So it seems to me that GetUserDataDir() adds the current editor/python
session name to the actual data dir (which is what the documentation
says it should do). It may or may not be related to your problem
directly, but if I were you I would run your script from the command
line and not in a IPython session. Of course I will welcome any
improvements to the way PersistentManager handles where the data is
stored...

The values that are returned by the wx.StandardPaths methods which contain the application name will use the name set in the wx.App object with SetAppName and/or SetVendorName. If those have not been set then it will fall back to the name of the executable, which is python or Pythonwin in the examples above.

So to have a consistent value for standard paths, for example when running direct from the .py files with different interpreter executables and also when running from a py2exe'd version, then you should set the wx.App's name and other related attributes.

I suspect that some state is maintained within the iPython session, which is
preventing PersistenceManager from finding the right directory on the nth
running where n>1.

Whenever you have more than one wx.App object being created within the lifetime of a single process you have the potential for little glitches like this. (And sometimes some big ones too.)

···

On 12/14/12 12:05 AM, Andrea Gavana wrote:

--
Robin Dunn
Software Craftsman