[PyQt] Detecting second copy of program in memory.

Phil Thompson phil at riverbankcomputing.com
Mon Jun 9 11:37:23 BST 2008


On Monday 09 June 2008 11:09:24 am Igor Prischepoff wrote:
> Hello, I'd like to detect if user tries to launch 2 copies of program.
>
> First one should rise from minimised state, and second copy should
> gracefully exit if detecting first one.
>
> So user should see that he is already running program.
> Here is my lame attempt (please see attachment).
>
> Generally it works, but problem is:
> I can not receive events until app.exec_() is called.
> So second copy is showing QMainWindow object and _only then_ exits...
> Just run main.py and then run it again not closing first one to see
> blinking of second copy.
>
> Is there a way to make it more clever way (not showing QMainWindow)?
>
> ---
> igor at tyumbit.ru

If you are using Qt v4.4 then a solution based on QSharedMemory should be 
simpler and probably work better.

Phil


More information about the PyQt mailing list