How to test if app already loaded

How would it test to ensure that their is only one instance of my wxPython app loaded at one time ??

···

Geoff Skerrett

Murray, Skerrett & Associates, Jonas Business Software

Phn: 902-461-0079 ~ Fax:902-461-9559 ~ Mob: 516-220-9723

Hi Geoff,

How would it test to ensure that their is only one instance of my wxPython
app loaded at one time ??

Try something like this:

class YourApp(wx.App):

    def OnInit(self):

        self.name = "YourApp-%s" % (wx.GetUserId())
        self.instance = wx.SingleInstanceChecker(self.name)

        if self.instance.IsAnotherRunning():
            wx.MessageBox("You Already Have One Instance Running", "Error")
            return False

        frame = YourAppFrame(None)
        frame.Show()

        return True

    def OnExit(self):

        del self.instance

:smiley:

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.virgilio.it/infinity77/

···

On 5/24/07, Geoff Skerrett wrote:

Geoff Skerrett ha scritto:

How
would it test to ensure that their is only one instance of my wxPython
app loaded at one time ??


Geoff Skerrett

Murray, Skerrett
& Associates, Jonas Business Software

Phn: 902-461-0079 ~
Fax:902-461-9559 ~ Mob: 516-220-9723

You can use a lock-file system, as:

On Windows:

win32file.CreateFile( <path_file>, <filename>) ,

GENERIC_READ | GENERIC_WRITE, 0, None, OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL, 0)

On Unix: ( linux & mac ):

fcntl.lockf( os.open(<filename>, os.O_RDWR),

fcntl.LOCK_EX|fcntl.LOCK_NB )

You can utilize these methods at start-up: if it generate an exception,
another app is already open!!!

Great, not!!

Bye

···

//\ariano Di Felice

Java PHP Python Ruby programmer

with MySQL, PostgreSql, SQLite and Oracle support

Linux Platform Developer

Tel. 0735 703735
Cell +39 339 6407211

mariano.difelice@gmail.com

Hi Mariano,

···

On 5/24/07, Mariano Di Felice wrote:

You can use a lock-file system, as:
On Windows:
    win32file.CreateFile( <path_file>, <filename>) , GENERIC_READ |
GENERIC_WRITE, 0, None, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0)
On Unix: ( linux & mac ):
    fcntl.lockf( os.open(<filename>, os.O_RDWR), fcntl.LOCK_EX|fcntl.LOCK_NB
)

You can utilize these methods at start-up: if it generate an exception,
another app is already open!!!
Great, not!!

wxPython already does this for you, platform independently. You don't
even have to bother about platform-specific code to do that. Just see
the post I sent few minutes ago.

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.virgilio.it/infinity77/

Ok Andrea, grazie mille!!!

Andrea Gavana ha scritto:

···

Hi Mariano,

On 5/24/07, Mariano Di Felice wrote:

You can use a lock-file system, as:
On Windows:
    win32file.CreateFile( <path_file>, <filename>) , GENERIC_READ |
GENERIC_WRITE, 0, None, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0)
On Unix: ( linux & mac ):
    fcntl.lockf( os.open(<filename>, os.O_RDWR), fcntl.LOCK_EX|fcntl.LOCK_NB
)

You can utilize these methods at start-up: if it generate an exception,
another app is already open!!!
Great, not!!

wxPython already does this for you, platform independently. You don't
even have to bother about platform-specific code to do that. Just see
the post I sent few minutes ago.

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.virgilio.it/infinity77/

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

--
/\/\ariano Di Felice
Java PHP Python Ruby programmer
with MySQL, PostgreSql, SQLite and Oracle support
Linux Platform Developer
mariano.difelice@gmail.com
Tel. 0735 703735
Cell +39 339 6407211

Ok Andrea, grazie mille!!!

Andrea Gavana ha scritto:

···

Hi Mariano,

On 5/24/07, Mariano Di Felice wrote:

You can use a lock-file system, as:
On Windows:
    win32file.CreateFile( <path_file>, <filename>) , GENERIC_READ |
GENERIC_WRITE, 0, None, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0)
On Unix: ( linux & mac ):
    fcntl.lockf( os.open(<filename>, os.O_RDWR), fcntl.LOCK_EX|fcntl.LOCK_NB
)

You can utilize these methods at start-up: if it generate an exception,
another app is already open!!!
Great, not!!

wxPython already does this for you, platform independently. You don't
even have to bother about platform-specific code to do that. Just see
the post I sent few minutes ago.

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.virgilio.it/infinity77/

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

--
/\/\ariano Di Felice
Java PHP Python Ruby programmer
with MySQL, PostgreSql, SQLite and Oracle support
Linux Platform Developer
mariano.difelice@gmail.com
Tel. 0735 703735
Cell +39 339 6407211