eg.Scheduler¶
-
class
eg.
Scheduler
[source]¶ Sometimes you want to execute some code at a specified time or after a specified time period. EventGhost includes a small scheduler, that helps you to accomplish this.
EventGhost creates a single instance of this class that is accessible as
eg.scheduler
.-
AddShortTask
(waitTime, func, *args, **kwargs)[source]¶ This function will call the callable func after waitTime seconds (expressed as a floating point number) with optional parameters, by adding it to the scheduler’s queue. A little example:
def MyTestFunc(myArgument): print "MyTestFunc was called with:", repr(myArgument) eg.scheduler.AddShortTask(10.0, MyTestFunc, "just some test data")
Ten seconds after invocation of the code it will print the following message to the log:
MyTestFunc was called with: 'just some test data'
The function will return an object, that you can use as the task identifier for
CancelTask()
.Arguments: - waitTime
The time to wait in floating point seconds.
- func
The callable to invoke after the time has elapsed.
- *args
Optional positional arguments for the callable.
- **kwargs
Optional keyword arguments for the callable.
Returns: An object to identify the task.
-
AddShortTaskAbsolute
(startTime, func, *args, **kwargs)[source]¶ This does the same as
AddShortTask()
, but the startTime parameter specifies an absolute time expressed in floating point seconds since the epoch. Take a look at the documentation of Python’s time module, for more information about this time format. Again a little example:import time startTime = time.mktime((2007, 8, 15, 16, 53, 0, 0, 0, -1)) eg.scheduler.AddShortTaskAbsolute(startTime, eg.TriggerEvent, "MyEvent")
This will trigger the event “Main.MyEvent” at 16:53:00 on 15 August 2007. If you run this code after this point of time, the
eg.TriggerEvent()
will be called immediately.
-
CancelTask
(task)[source]¶ This will cancel a task formerly added by
AddShortTask()
orAddShortTaskAbsolute()
, if the task hasn’t been started yet.If the task has already been called or simply wasn’t added before, the function will raise an IndexError.
-