Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #92547

Re: Detect if specific Python.app instance is already running

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!border1.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'apps,': 0.07; 'attributes': 0.07; 'dynamically': 0.07; 'interpreter.': 0.07; 'modifying': 0.07; 'skip:/ 10': 0.07; 'scripts': 0.09; 'app,': 0.09; 'instances.': 0.09; 'path.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'url:mac': 0.09; 'python': 0.11; 'suggest': 0.15; 'apps': 0.15; '"information': 0.16; 'already,': 0.16; 'bundles': 0.16; 'finder': 0.16; 'goal,': 0.16; 'great!': 0.16; 'inst': 0.16; 'luck!': 0.16; 'py2app': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'skip:n 50': 0.16; 'subject:already': 0.16; 'subject:instance': 0.16; 'there?': 0.16; 'tkinter.': 0.16; 'url:documentation': 0.16; 'url:general': 0.16; 'wrote:': 0.16; 'app': 0.16; 'looked': 0.16; 'detect': 0.18; 'instance,': 0.18; 'script.': 0.18; 'gui': 0.18; 'prevent': 0.20; 'trying': 0.22; '(by': 0.22; 'assuming': 0.22; 'enforce': 0.22; 'tkinter': 0.22; 'defined': 0.23; 'bit': 0.23; '2015': 0.23; "haven't": 0.24; 'second': 0.24; 'header:User- Agent:1': 0.26; 'idea': 0.26; 'question': 0.26; 'header:X -Complaints-To:1': 0.26; '(e.g.': 0.27; 'command': 0.28; 'necessary,': 0.29; 'guess': 0.29; 'launch': 0.29; 'certainly': 0.31; 'e.g.': 0.31; 'mention': 0.31; 'certain': 0.31; 'run': 0.32; 'similar': 0.32; 'gets': 0.32; 'probably': 0.32; 'framework': 0.32; 'problem': 0.33; 'usually': 0.33; 'instances': 0.33; 'lock': 0.33; 'skip:/ 20': 0.33; 'another': 0.34; 'case,': 0.34; 'running': 0.34; 'file': 0.34; 'useful': 0.35; 'wrong': 0.35; 'could': 0.35; 'to:addr:python-list': 0.35; 'done': 0.35; 'clear': 0.35; 'files,': 0.35; 'i.e.': 0.35; 'instance': 0.35; 'something': 0.35; 'really': 0.35; 'list': 0.35; 'expected': 0.35; 'but': 0.36; 'too': 0.36; 'there': 0.36; 'thanks': 0.36; '(and': 0.36; 'monday,': 0.36; 'url:library': 0.36; 'so,': 0.37; "didn't": 0.37; 'setting': 0.37; 'subject:: ': 0.37; 'charset:us-ascii': 0.37; 'one,': 0.37; 'rather': 0.38; 'received:org': 0.38; 'someone': 0.38; 'end': 0.39; 'test': 0.39; 'does': 0.39; 'to:addr:python.org': 0.39; 'sure': 0.40; 'mark': 0.40; 'some': 0.40; 'your': 0.60; 'hope': 0.61; 'close': 0.61; 'default': 0.61; 'identify': 0.61; 'provide': 0.61; 'taking': 0.62; 'more': 0.62; 'complete': 0.63; 'different': 0.64; 'goal': 0.64; 'better.': 0.66; 'believe': 0.67; 'sound': 0.72; 'received:204': 0.75; 'url:i': 0.77; 'article': 0.77; 'alright,': 0.84; 'presumably': 0.84; 'reply!': 0.84; 'simple:': 0.84; 'trickery': 0.84; 'url:reference': 0.91; 'tricky': 0.93
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Ned Deily <nad@acm.org>
Subject Re: Detect if specific Python.app instance is already running
Date Fri, 12 Jun 2015 12:08:35 -0700
References <a3be1707-0eae-46fa-9921-e9c145816ad5@googlegroups.com> <11e093d5-b78e-4ac6-9a7f-649cb2c2c942@googlegroups.com> <mailman.281.1433718479.13271.python-list@python.org> <6651a781-abe1-4f25-b1f3-1f849776d060@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=US-ASCII
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host 204.28.118.160
User-Agent MT-NewsWatcher/3.5.3b3 (Intel Mac OS X)
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.435.1434136134.13271.python-list@python.org> (permalink)
Lines 76
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1434136134 news.xs4all.nl 2883 [2001:888:2000:d::a6]:34077
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:92547

Show key headers only | View raw


In article <6651a781-abe1-4f25-b1f3-1f849776d060@googlegroups.com>,
 Andrei <andrei.fokau@gmail.com> wrote:

> On Monday, June 8, 2015 at 1:08:07 AM UTC+2, Ned Deily wrote:
> > In article <11e093d5-b78e-4ac6-9a7f-649cb2c2c942@googlegroups.com>,
> >  Andrei wrote:
> > > Alright, I have had some development in 
> > > http://stackoverflow.com/questions/30694560/detect-if-specific-python-app-
> > > inst
> > > ance-is-already-running and can prevent running multiple instances of the 
> > > same app/script (by lockf), but I still need to identify which Python.app 
> > > instance is running certain script. I guess it's more Cocoa-related 
> > > question 
> > > but I hope someone had same problem with tkinter etc.
> > 
> > Can you give a more complete explanation of the goal, i.e. what you are 
> > trying to end up with here, rather than the steps you are taking to get 
> > there?  It's not at all clear to me what your goal is and the cumbersome 
> > steps you find you have to take suggest that you might be going down the 
> > wrong path.  OS X apps usually don't have to resort to such hacks.  If 
> > you haven't already, make sure you have looked at the "Information 
> > Property List Key Reference" for OS X (and iOS) apps.  For instance, key 
> > LSMultipleInstancesProhibited *might* be useful if you really only want 
> > to ensure that there is only instance of an app launched.
> > 
> > https://developer.apple.com/library/mac/documentation/General/Reference/I
> > nfoPlistKeyReference/Articles/LaunchServicesKeys.html
> > 
> > -- 
> >  Ned Deily
> 
> 
> Hi Ned,
> Thanks for your reply! The problem is a bit tricky as I see it. Multiple 
> instances of Python.app needs to be run since it may run different tkinter 
> apps etc. What I need is rather simple:
> 
> 1. start app, mark the instance with tkinter app name
> 2. start another one, detect that the same instance is already running and 
> identify it
> 3. focus on the first instance, close the second one
> 
> I have solved it with a lock file and a pid file (I guess I could use just 
> one file for both jobs, but didn't have time to test it yet). I believe it 
> could be done without files, i.e. by setting some public attributes on app 
> instances. I could probably also use OS X key storage for this but it gets 
> too similar to the file approach and I am not sure if it's any better.
> 
> I may be wrong in my thinking. If so, just let me know :)

If you have something that works for you, great!  A question that 
remains is: how are you launching all these apps?  You mention tkinter 
so presumably these are "gui" apps.  On OS X, native "gui" apps are 
expected to be packaged as app bundles and launched via Launch Services, 
e.g. by double-clicking in the Finder or by /usr/bin/open from the 
command line.  Framework installs of Python cheat a bit and provide a 
default Python.app bundle buried in the framework and do some trickery 
when python is started conventionally from the command line (e.g. via 
something like /usr/local/bin/python) to allow the process to be 
promoted to a gui app, if necessary, like when using Tk from tkinter.  
If you need gui apps, the most "Mac-thonic" approach would be to use 
something like py2app to produce each different app as a unique gui app 
bundle and then, assuming each app's Info.plist are defined properly, OS 
X will enforce that only one instance of each app is running at a time.  
But that works only if they are launched as apps rather than run as 
scripts from the Python interpreter.  Of course, this all may be 
overkill for what you are trying to do but dynamically modifying app 
bundles or some such certainly does not sound like a good idea for lots 
of reasons.  

In any case, good luck!

-- 
 Ned Deily,
 nad@acm.org

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Detect if specific Python.app instance is already running Andrei <andrei.fokau@gmail.com> - 2015-06-07 07:31 -0700
  Re: Detect if specific Python.app instance is already running Andrei <andrei.fokau@gmail.com> - 2015-06-07 12:54 -0700
    Re: Detect if specific Python.app instance is already running Ned Deily <nad@acm.org> - 2015-06-07 16:07 -0700
      Re: Detect if specific Python.app instance is already running Andrei <andrei.fokau@gmail.com> - 2015-06-08 01:32 -0700
        Re: Detect if specific Python.app instance is already running Laura Creighton <lac@openend.se> - 2015-06-08 20:21 +0200
        Re: Detect if specific Python.app instance is already running Ned Deily <nad@acm.org> - 2015-06-12 12:08 -0700

csiph-web