how to know if a script is running

  Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
solexalex Offline
Skilled Python Coder
Posts: 706
Joined: Jul 2004
Reputation: 6
Post: #1
is there any way to know from, let say, script 'father', if a 'child' script is running ?
something like :
isrunning(path+ "pythonscript.py") :: return true if pythonscript.py is actually running (shown with (running...) after the script name)

thanks in advance for any help
find quote
Nuka1195 Offline
Skilled Python Coder
Posts: 3,938
Joined: Dec 2004
Reputation: 17
Post: #2
in the child:

Quote:import yourownmodule # maybe even blank .py file

in the parent:

Quote:m = sys.modules
r = false
for items in m:
if (items == 'yourownmodule'):
r = true

For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
find quote
solexalex Offline
Skilled Python Coder
Posts: 706
Joined: Jul 2004
Reputation: 6
Post: #3
cheers !
i'm not sure if it is really what i need...
let me explain a bit more:
the script i'm working on needs another script running in background.
my script is somethin that connect to a http url to get a video stream and save it on hdd.
the script running in background is a proxy, that just catch the http request (from my script), proxy it to a server using rtsp, and sending back on http the video stream.
so actually, i :
1- start the proxy script running in a loop waiting for http connection
2- start my script to select a video channel and send the http request for video stream
so in my mind, both script are running separetely, no import from one in the other... i'm not very clever in python, but i do my best, so importing a module in another one is pretty tricky as i'm never really sure how this should be done...

so can you confirm me, that if a script is shown as (running...) inside scripts screen, it will appear in 'sys.modules' ?

anyway, i will have some test using your idea and let you know what are my results
find quote
Rockstarr Offline
Skilled Python Coder
Posts: 78
Joined: Mar 2006
Reputation: 0
Location: Leipzig, Germany
Post: #4
hi.

i dont know if this still works:

if you declare a var in a script and dont delete it, another script can get this var.

script 1:
Quote:testvar = "test"

script 2:
Quote:print testvar
>> test
find quote
Nuka1195 Offline
Skilled Python Coder
Posts: 3,938
Joined: Dec 2004
Reputation: 17
Post: #5
if you create a "dummy.py" (just an empty text file) and import that in child script. (import dummy) it will show up in sys.modules list in the paraent if the script is still running.

but maybe check one of the os.spawn*(). this maybe what you want?

For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
find quote
solexalex Offline
Skilled Python Coder
Posts: 706
Joined: Jul 2004
Reputation: 6
Post: #6
Hi !
I know it has been a long time since this question.
I tried the import of a dummy library and it works just fine. Not sure it is a very clean way to do it but it works.
find quote
trignum5 Offline
Junior Member
Posts: 17
Joined: Aug 2006
Reputation: 0
Post: #7
One more idea from the bad programmerSmile
-Create a file when your script loads
-Delete the file on exit
-Double check in autoexec.py at boot that there isn't a renegade copy on disk due to a crash

Regarding the variable scope, I found that it needed to be declared globally if another script had any chance of finding it, but even then I sometimes got unexpected results..
Python is a funny language.. One of the simplest to use, but one of the more difficult to understand its scope
find quote