[wxPython-users] Having a single instance and forwarding document open requests

Doug Anderson doug at vitamindinc.com
Thu Sep 27 07:02:37 PDT 2007


Thanks for all the quick responses.

I decided against TCP socket, mostly because:
- You've got to pick an arbitrary port and hardcode it.  If that port  
is taken, you are stuck with a really obscure failure case (not  
common, but I'm paranoid).
- You can't support multi-user systems well (each user should have  
their own single instance), since their TCP sockets would collide.

I've never used XMLRCP, but my quick glance at it indicates that it  
suffers from similar problems (correct me if I'm wrong), since it  
runs on TCP.


I've almost got a system working that uses files.  I have a listener  
thread watching a special directory for the appearance of files,  
which are used as a form of communication.  Not great, but it works  
even on windows (which doesn't seem to have mkfifo).  I figure out  
the listener thread with the SingleInstanceChecker (the warnings  
about stale lock files are a bit annoying, though I found a way  
around that with some google searching).


I guess my "kludgy" comment was more that with all of the advanced  
features of wxpython elsewhere, it surprised me that I had to jump  
through so many hoops and make so many design tradeoffs to solve what  
seemed like a relatively common problem.  ...but I know, programming  
is filled with such things.  ;)  WxPython at least makes it so I  
don't have to jump through as many hoops elsewhere in my code!

-Doug

---

On Sep 26, 2007, at 10:23 PM, Dusty Phillips wrote:

> On 26/09/2007, Dusty Phillips <buchuki at gmail.com> wrote:
>>> For those unfamiliar, let me explain.  I want it so that if someone
>>> double-clicks on one of my document files, it will either:
>>> - If no other copy of the app is running, it will start up the  
>>> application
>>> and open the document.
>>> - If another copy of the app is running, it will just tell that
>>> already-running copy to open the document.
>>>
>>> Another way to put it: I'd like to work like Visual Studio works  
>>> on Windows:
>>> opening a .c file from the file explorer doesn't open a separate  
>>> copy of
>>> visual studio.
>>
>> One interesting (aka: weird) way to do this is using tcp/ip, which is
>> supported on all modern systems.
>
>>> * My best idea so far is to use the wx.SingleInstanceChecker.   
>>> With it, I
>>> can prevent the second copy of the app from starting up, but I can't
>>> communicate with it to tell it which documents to open.  I could  
>>> use an out
>>> of band communication method (TCP sockets, a file, ...), but that  
>>> seems very
>>> kludgy.
>
> Whoops, maybe I should have finished reading. ;-) I apologize. I
> personally disagree about TCP sockets being kludgy. They are fully
> supported, completely event driven, and don't take up a lot of
> overhead. Since you're connecting to localhost, you can probably get
> away with UDP sockets, with even less overhead; its unlikely packets
> would be dropped.
>
> Dusty
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wxPython-users-unsubscribe at lists.wxwidgets.org
> For additional commands, e-mail: wxPython-users- 
> help at lists.wxwidgets.org
>





More information about the wxpython-users mailing list