# Launch program if not running

**URL:** <https://discourse.nodered.org/t/launch-program-if-not-running/8374>\
**Category:** General\
**Created:** [25 February 2019 15:09 UTC](https://discourse.nodered.org/t/launch-program-if-not-running/8374 "2019-02-25T15:09:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kxkayser](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kxkayser/32/6301_2.png) [@kxkayser](https://discourse.nodered.org/u/kxkayser)\
**Post date:** [25 February 2019 15:09 UTC](https://discourse.nodered.org/t/launch-program-if-not-running/8374/1 "2019-02-25T15:09:06Z")

</div>

Hi all. Another newbe question. I have a flow which accepts input from Alexa and interacts with a Python program via mqtt. I only want to launch the program if it's not running. Seems like this should be simple but I can't figure out the logic. I can easily set up mqtt topics and commands to report that the program is running but there are no messages to listen for if the program is not running. Any help would be appreciated.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [25 February 2019 16:16 UTC](https://discourse.nodered.org/t/launch-program-if-not-running/8374/2 "2019-02-25T16:16:04Z")

</div>

Is the python program your own? If so then the easiest solution might be to modify it slightly to detect whether it is already running when it starts, and just exit immediately if so.  
Alternatively then you could run something like `ps -aux` from an exec node and interpret the result to see if it is running.

---

<div class="post-metadata">

**Author:** ![moebius](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/moebius/32/2872_2.png) [@moebius](https://discourse.nodered.org/u/moebius)\
**Post date:** [25 February 2019 16:52 UTC](https://discourse.nodered.org/t/launch-program-if-not-running/8374/3 "2019-02-25T16:52:51Z")

</div>

LMGTFY  
[https://www.google.com/search?q=python+single+instance+application](https://www.google.com/search?q=python+single+instance+application)

1. Result

> The following code should do the job, it is cross-platform and runs on Python 2.4-3.2. I tested it on Windows, OS X and Linux.
> 
> from tendo import singleton  
> me = singleton.SingleInstance() # will sys.exit(-1) if other instance is running  
> The latest code version is available singleton.py. Please file bugs here.
> 
> You can install tend using one of the following methods:
> 
> easy\_install tendo  
> pip install tendo  
> manually by getting it from [tendo · PyPI](http://pypi.python.org/pypi/tendo)

---

<div class="post-metadata">

**Author:** ![kxkayser](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kxkayser/32/6301_2.png) [@kxkayser](https://discourse.nodered.org/u/kxkayser)\
**Post date:** [25 February 2019 17:21 UTC](https://discourse.nodered.org/t/launch-program-if-not-running/8374/4 "2019-02-25T17:21:22Z")

</div>

Brilliant guys. Thanks for the quick response.
