1

I have here a python program written for an Enigma 2 Linux Set top box: VirtualZap Python program for Enigma 2 based set top boxes

I want to automatize the execution of the following function every minute:

def aktualisieren(self):  
    self.updateInfos()

You can find the defined function within line 436 and 437.

My problem is that class VirtualZap contains only one constructor but no main method with the actual program run, therefore it is difficult to implement threads or coroutines. Is there any possibility to automatize the execution of the aktualisieren function?

falsetru
  • 357,413
  • 63
  • 732
  • 636

1 Answers1

0

There is an Advanced Python Scheduler

from apscheduler.schedulers.blocking import BlockingScheduler

def aktualisieren(self):  
    self.updateInfos()

scheduler = BlockingScheduler()
scheduler.add_job(aktualisieren, 'interval', hours=1)
scheduler.start()
MichaelMMeskhi
  • 659
  • 8
  • 26
  • Thanks for the fast response @MichaelMMeshki – Andrew Williams Jun 15 '17 at 19:06
  • But I mixed up the versions. Enigma 2 is still using Python 2.7.9. Therefore the apscheduler can´t be used ;( – Andrew Williams Jun 15 '17 at 19:06
  • @AndrewWilliams have you tried `sched` https://docs.python.org/2/library/sched.html – MichaelMMeskhi Jun 15 '17 at 19:09
  • @MichaelMMeshki Yes, I treid several times but it didn´t work. The aktualisieren() method is part of the VirtualZap class, but it isn´t being instantiated anywhere in the code. Something has to load it and calls it through the passed session in the main() function but without a clear order of execution I cannot really establish where to add the modifications to ensure that something gets executed in scheduled periods. Do you have any further ideas? – Andrew Williams Jun 16 '17 at 06:33
  • @Andrew Williams Why not try and instantiate it in the main and add the scheduler there? – MichaelMMeskhi Jun 16 '17 at 06:43
  • @Andrew Williams or just add the `updateInfos()` to some other function that can be scheduled – MichaelMMeskhi Jun 16 '17 at 06:44
  • Can you please give me some code example and where to put it? I am not able to manage it ;( – Andrew Williams Jun 16 '17 at 08:16
  • @AndrewWilliams What I mean is add your `aktualisieren()` method into for example `autostart()` function. Put it as a method inside another function that you know is always run from main and add the scheduler too. – MichaelMMeskhi Jun 16 '17 at 12:22