Page 1 of 3

eg.scheduler

Posted: Thu May 08, 2014 5:29 pm
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

Re: eg.scheduler

Posted: Fri May 09, 2014 8:06 am
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

Re: eg.scheduler

Posted: Mon May 12, 2014 6:14 pm
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

Re: eg.scheduler

Posted: Mon May 12, 2014 8:23 pm
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.

Re: eg.scheduler

Posted: Sat May 17, 2014 10:21 am
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

Re: eg.scheduler

Posted: Sun May 18, 2014 5:00 am
by krambriw
Excellent, thank you
Updated my systems

BestR Walter

Re: eg.scheduler

Posted: Sun May 18, 2014 7:31 am
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

Re: eg.scheduler

Posted: Sun May 18, 2014 11:11 am
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? ;-)

Re: eg.scheduler

Posted: Sun May 18, 2014 11:51 am
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

Re: eg.scheduler

Posted: Mon May 19, 2014 4:58 pm
by Sem;colon
Ok, I didn't even know that somebody's working on that :D

Re: eg.scheduler

Posted: Wed Jun 04, 2014 2:28 am
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?

Re: eg.scheduler

Posted: Thu Jun 05, 2014 7:14 am
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

Re: eg.scheduler

Posted: Thu Jun 05, 2014 7:44 am
by WharfRat
If this is where you need to be notified about it, then: PHX01RN v3.0.1

Re: eg.scheduler

Posted: Thu Jun 05, 2014 4:29 pm
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

Re: eg.scheduler

Posted: Sun Aug 10, 2014 6:37 am
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