How to detect Python execution environment

Python and python framework

Moderator: leecollings

Post Reply
Number8
Posts: 374
Joined: Friday 23 May 2014 7:55
Target OS: Linux
Domoticz version: 2022.1
Location: Saint Pierre de Jards
Contact:

How to detect Python execution environment

Post by Number8 »

Hello,
Is there a way to detect Python scripts execution environment, that is interactive (from a terminal session) or directly from Domoticz
Thank you
Debian buster on NUC and three RPi with buster.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: How to detect Python execution environment

Post by waaren »

@Number8,

do you mean

$which python3.5
/usr/local/bin/python3.5

$which python
/usr/bin/python

$python --version
Python 2.7.12

$python3.5 --version
Python 3.5.1
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
SweetPants

Re: How to detect Python execution environment

Post by SweetPants »

or:

/usr/bin/env python
Python 2.7.6 (default, Oct 26 2016, 20:30:19)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Number8
Posts: 374
Joined: Friday 23 May 2014 7:55
Target OS: Linux
Domoticz version: 2022.1
Location: Saint Pierre de Jards
Contact:

Re: How to detect Python execution environment

Post by Number8 »

Thanks for your replies. However this is not what I'm looking for. Inside a script, I want to detect whether Python has been launched from a terminal session (SSH), that is with direct user interaction, or from a control within Domoticz?
Is there a way to detect that?
Debian buster on NUC and three RPi with buster.
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: How to detect Python execution environment

Post by EddyG »

Shell variable PPID -> parent pid
So 'echo $PPID' gives the parent PID, go from there.
Number8
Posts: 374
Joined: Friday 23 May 2014 7:55
Target OS: Linux
Domoticz version: 2022.1
Location: Saint Pierre de Jards
Contact:

Re: How to detect Python execution environment

Post by Number8 »

Thanks EddyG, this is the idea I was looking for.
Debian buster on NUC and three RPi with buster.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest