Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details

If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.

eg.scheduler

Do you have questions about writing plugins or scripts in Python? Meet the coders here.
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

eg.scheduler

Post by Pako »

Some time ago I discovered that eg.scheduler does not behave quite as I expected.
I thought eg.scheduler only starts a scheduled task, and then it will be released for another task.
But it is not. It is busy all the time, when the task is performed. Only when the job is completed, eg.scheduler can start another.
You can check this with a simple test:

Code: Select all

def fc(x, y = 'Y'):
    import time
    print "Long task start: ",time.ctime()
    print "x, y =",x,y
    time.sleep(10.0)
    print "Long task stop: ",time.ctime()

def TEST():
    eg.scheduler.AddTask(0.01, fc, "X", y="YY")
    eg.scheduler.AddTask(5.0, fc, "XX", y="YYYY")
TEST()
So be careful with it, it is not correct to schedule tasks whose execution time is long!
This can cause a delayed start another task (for example, from another plugin).


However, I tried to make some improvements.
I added methods AddLongTask and AddLongTaskAbsolute.
The syntax is exactly the same, only a task is run in a separate thread, so it does not matter how long it takes.
You can try the same test:

Code: Select all

def fc(x, y = 'Y'):
    import time
    print "Long task start: ",time.ctime()
    print "x, y =",x,y
    time.sleep(10.0)
    print "Long task stop: ",time.ctime()

def TEST2():
    eg.scheduler.AddLongTask(0.01, fc, "XXX", y="YYYYYY")
    eg.scheduler.AddLongTask(5.0, fc, "XXXX", y="YYYYYYYY")
TEST2()
Can I get some feedback from you?

Thanks, Pako
Attachments
Scheduler.py
(5.64 KiB) Downloaded 221 times
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: eg.scheduler

Post by krambriw »

Dear Pako,
This is a critical finding you have made I think. It is important to be fixed as you propose. I have had no time to test yet but I agree that it needs to be corrected.

Kind regards, Walter
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: eg.scheduler

Post by krambriw »

Dear Pako,
After testing, I can say that now after your (bug)fix it works as it should and the way I believed it was working already.
I would rate this as a serious bug and I can't believe that Bitmonster would have objected if he would have been around.

The old function was in fact serialized, after you fixed it, scheduling is now happening in parallel and independent of other scheduled tasks.

My suggestion is to replace the current scheduler with your fixed version but keep the method names as before to keep compatibility with all developed plugins and other customized scripts.

If you still would keep both, I will anyway always use your fixed version. I cannot see that I am interested in serialized scheduling ever, especially since I have no control when it will be executed, it is so dependent of whatever could be in pipeline for current execution. If I need to serialize something, I would do that with macros and relevant triggers.

Do you think this version of scheduler.py can be used also to update not only the latest version of EG? I have a system that is still running a bit older version (1534) and I have not planned to upgrade very shortly...

Best regards and thank you for finding this
Walter
Sem;colon
Plugin Developer
Posts: 625
Joined: Sat Feb 18, 2012 10:51 am
Location: Germany

Re: eg.scheduler

Post by Sem;colon »

Hello Pako,

as far as I can tell it works fine. :D
krambriw wrote: My suggestion is to replace the current scheduler with your fixed version but keep the method names as before to keep compatibility with all developed plugins and other customized scripts.
I agree, that would improve many things.
The old function could be renamed to something else, eg. AddSerialTask.
For plugins I don't see a problem with doing that, most of the people (including me) thought it would work the other way anyway.

The only thing that needs to be checked is if the core plugins and libs are demanding on the old function.
If you like my work, Image me a drink :wink:
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: eg.scheduler

Post by Pako »

Thank you for your response.
Sem;colon wrote:
krambriw wrote: My suggestion is to replace the current scheduler with your fixed version but keep the method names as before to keep compatibility with all developed plugins and other customized scripts.
I agree, that would improve many things.
The old function could be renamed to something else, eg. AddSerialTask.
I actually meant the same solution.
Just for testing purposes I did it backwards.
Now I therefore present the final version.
Original methods are called AddShortTask and AddShortTaskAbsolute.
In some cases, it is probably unnecessary to use the new versions, which starts all jobs through Thread.
Examples are plugins SchedulGhost and Timer (task only triggers event).
Pako
Attachments
Scheduler.py
(5.68 KiB) Downloaded 216 times
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: eg.scheduler

Post by krambriw »

Excellent, thank you
Updated my systems

BestR Walter
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: eg.scheduler

Post by Pako »

Dear Walter,
krambriw wrote:Updated my systems
If you are using SchedulGhost plugin, then you must make some changes in it:
the string AddTask replace using the string AddShortTask
and the string AddTaskAbsolute replace using the string AddShortTaskAbsolute.
Otherwise it will not work properly with the new eg.Scheduler module !

Best regards,
Pako
Sem;colon
Plugin Developer
Posts: 625
Joined: Sat Feb 18, 2012 10:51 am
Location: Germany

Re: eg.scheduler

Post by Sem;colon »

Pako wrote:If you are using SchedulGhost plugin, then you must make some changes in it
It's time for a new EventGhost release and integrate both changes, don't you think? ;-)
If you like my work, Image me a drink :wink:
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: eg.scheduler

Post by Pako »

Sem;colon wrote:It's time for a new EventGhost release and integrate both changes, don't you think? ;-)
I am thinking about it for a long time.
But I did not want to disrupt the plans to change the repository to GitHub.
I do not know, what will happen if I continue to use SourceForge/SVN (if any work, which did cfull, will not be in vain and it will be necessary to do it again).

Pako
Sem;colon
Plugin Developer
Posts: 625
Joined: Sat Feb 18, 2012 10:51 am
Location: Germany

Re: eg.scheduler

Post by Sem;colon »

Ok, I didn't even know that somebody's working on that :D
If you like my work, Image me a drink :wink:
Sem;colon
Plugin Developer
Posts: 625
Joined: Sat Feb 18, 2012 10:51 am
Location: Germany

Re: eg.scheduler

Post by Sem;colon »

Pako wrote:But I did not want to disrupt the plans to change the repository to GitHub.
I do not know, what will happen if I continue to use SourceForge/SVN (if any work, which did cfull, will not be in vain and it will be necessary to do it again).
OK, but was there any progress the last months?
I mean, the latest EventGhost version is over a year old, people may start thinking EventGhost is dead..
Probably we should stick to SVN?
If you like my work, Image me a drink :wink:
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: eg.scheduler

Post by Pako »

I agree - it would be good to release a new version.
I ask for help. I would like to not forget anything.
Please - reminding me, what changes (plugins and core) should not be missing in the new version!
Note:
I intend to add some libraries (such as tornado, paramiko, requests) into install file too.
Do you have any suggestions for other useful libraries?

Pako
User avatar
WharfRat
Experienced User
Posts: 159
Joined: Wed Dec 25, 2013 11:56 am

Re: eg.scheduler

Post by WharfRat »

If this is where you need to be notified about it, then: PHX01RN v3.0.1
EventGhost 0.4.1.r1640
PHX01RN plugin v3.0.1
Windows XP 32bit (v5.1 Build 2600 Service Pack 2)
Windows7 64bit (v6.1 Build 7601 Service Pack 1)
Sem;colon
Plugin Developer
Posts: 625
Joined: Sat Feb 18, 2012 10:51 am
Location: Germany

Re: eg.scheduler

Post by Sem;colon »

Pako wrote:Please - reminding me, what changes (plugins and core) should not be missing in the new version!
The ones from me are all in that topic:
viewtopic.php?f=12&t=5671
Pako wrote:I intend to add some libraries (such as tornado, paramiko, requests) into install file too.Do you have any suggestions for other useful libraries?
That's a good idea! :D
If you like my work, Image me a drink :wink:
TRIROG1
Posts: 45
Joined: Fri Aug 08, 2014 10:07 pm

Re: eg.scheduler

Post by TRIROG1 »

quick question

in my script

Code: Select all

import urllib

if not "Shutters_movie_timeout" in eg.globals.__dict__:
    eg.globals.Shutters_movie_timeout = 0
if not "Shutters_movie_mode" in eg.globals.__dict__:
    eg.globals.Shutters_movie_mode = 0

def ResetTimer():
    print 'Timer expired-setting movie mode to 0'
    eg.globals.Shutters_movie_timeout = 0
    eg.globals.Shutters_movie_mode = 0
    
if eg.globals.Shutters_movie_timeout == 1:
    if eg.globals.Shutters_movie_mode == 1:
        print "Movie mode OFF"
        #urllib.urlopen('http://192.168.0.240:8080/movieoff')
        eg.globals.Shutters_movie_mode = 0
    else:
        print "Doing nothing - Movie mode OFF"
        
    eg.globals.Shutters_movie_timeout = 0

else:
    print 'Setting eg.globals.Shutters_movie_timeout to 1 and starting timer...'
    eg.globals.Shutters_movie_timeout = 1
    eg.scheduler.AddTask(10, ResetTimer)

i call the eg.scheduler.AddTask(10, ResetTimer) to check if a same event has been triggered twice quickly one after another (within 10 seconds) , but i would also like to use the eg.scheduler.CancelTask(task) to cancel the timer if the condition if eg.globals.Shutters_movie_timeout == 1 is met.

how can i use the command eg.scheduler.CancelTask() correctly to cancel this timer?

All help is appreciated!

EDIT:
I read in the manual that the eg.scheduler.AddTask should return an object, that you can use as the task identifier for CancelTask() - but i dont know how or where to get it ... the eventlog is empty?
this is all i get ...
08:37:39 Python Script
08:37:39 Setting eg.globals.Shutters_movie_timeout to 1 and starting timer...
08:37:50 Timer expired-setting movie mode to 0
Post Reply