Jump to content


Photo

Running a plugin (or python script) as a background task


  • Please log in to reply
7 replies to this topic

#1 Oliver.M.

  • Member
  • 12 posts

0
Neutral

Posted 29 July 2020 - 12:10

Hi All, 

 

I am working on a Python script to retrieve the SNR, BER and AGC from the web interface which is working great.

 

I now need this task to run in the background to gather the data every X number of minutes.

 

I have looked into using init.d to run the program on startup but this doesn't seem to work. I have also looked into using sessionStart on a standard plugin but found Engima2 would hang with the spinning wheel (because my program contained an infinite loop).

 

My most recent attempt consisted of using os.system to run the Python script from sessionStart but I found the python script isn't actually running... I don't know why because trying the same command from the Python shell does work so maybe this is a permissions issue. Ideally this is the route I would like to go down but I cannot get os.system to work...

 

I read somewhere online about the eAppContainer module but cannot find any details on how I may go about using this. 

 

Is anybody able to help me out with this?

 

Many thanks.



Re: Running a plugin (or python script) as a background task #2 mfaraj57

  • Senior Member
  • 1,588 posts

+284
Excellent

Posted 29 July 2020 - 15:58

os.system is bad choice because of two things

cause instability of the system and hang the startup until the task completed

you can use timer or eAppContainer module or threading



Re: Running a plugin (or python script) as a background task #3 betacentauri

  • PLi® Core member
  • 6,243 posts

+275
Excellent

Posted 29 July 2020 - 16:36

Cron would be also a solution.

Or use a timer which is started at sessionStart which calls a procedure every x seconds.
Xtrend ET-9200, ET-8000, ET-10000, OpenPliPC on Ubuntu 12.04

Re: Running a plugin (or python script) as a background task #4 littlesat

  • PLi® Core member
  • 51,888 posts

+589
Excellent

Posted 29 July 2020 - 17:13

Two option twisted or what I did with fallback tuner....(reading setting and epg)

WaveFrontier 28.2E | 23.5E | 19.2E | 16E | 13E | 10/9E | 7E | 5E | 1W | 4/5W | 15W


Re: Running a plugin (or python script) as a background task #5 MiLo

  • PLi® Core member
  • 13,967 posts

+295
Excellent

Posted 29 July 2020 - 19:06

os.system usually doesn't work, so don't use it.

 

If you want to run inside enigma2, use a timer. This will call your function when the timeout occurs. If what you're doing takes a long time, use a thread to prevent blocking the GUI. Follow the "twisted" manual, it probably has examples for both that you can try and test on your PC or outside enigma to save you tons of time trying to develop and debug on the board.

 

If your Python script reads from the webinterface, that's just silly. You are inside enigma2, so you can get the requested information straight from the horses mouth, i.e. wherever the webinterface gets it. Takes a bit of digging to find the routines, but will be much, much much more efficient so you also won't need a thread any more.


Real musicians never die - they just decompose

Re: Running a plugin (or python script) as a background task #6 Oliver.M.

  • Member
  • 12 posts

0
Neutral

Posted 29 July 2020 - 19:56

Thank you all for your suggestions and advice!!

 

I will see what I can do with timers and cron, Ideally cron as it simplifies things massively!

 

I had a brief look at cron earlier today but didn't get too far. When entering crontab -e in the terminal I was getting a page of "~" characters and I was unable to enter the correct command to run the script every 5 minutes.

Almost as if cron wasn't installed properly or corrupt... Maybe I just wasn't using it properly! I haven't really looked at cron before. Would it be possible for somebody to provide a brief overview of the commands I might need to use to setup cron?

 

I will see if I can rewrite my Python script to get the data directly from Enigma. Its an older script which was originally running on my PC so could do with an upgrade.

 

Many Thanks.



Re: Running a plugin (or python script) as a background task #7 betacentauri

  • PLi® Core member
  • 6,243 posts

+275
Excellent

Posted 29 July 2020 - 23:26

I guess crontab -e starts vi editor. Google how to use it.
Xtrend ET-9200, ET-8000, ET-10000, OpenPliPC on Ubuntu 12.04

Re: Running a plugin (or python script) as a background task #8 s3n0

  • Senior Member
  • 208 posts

+26
Good

Posted Yesterday, 11:00

I add the note that Cron must be installed in PLi.

It is not pre-installed (as in the case of other Enigma distributions).

So install it first ... for example via Shell:

opkg update && opkg install busybox-cron





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users