Package entropy :: Module misc :: Class TimeScheduled

Class TimeScheduled

source code


Multithreading class that wraps Python threading.Thread. Specifically, this class implements the timed function execution concept. It means that you can run timed functions (say every N seconds) and control its execution through another (main?) thread.

It is possible to set arbitrary, variable, delays and decide if to delay before or after the execution of the function provided at construction time. Timed function can be stopped by calling TimeScheduled.kill() method. You may find the example below more exhaustive:

>>> from entropy.misc import TimeScheduled
>>> time_sched = TimeSheduled(5, print, "hello world", 123)
>>> time_sched.start()
hello world 123 # every 5 seconds
hello world 123 # every 5 seconds
hello world 123 # every 5 seconds
>>> time_sched.kill()
Instance Methods
None
__init__(self, delay, *args, **kwargs)
TimeScheduled constructor.
source code
 
start(self)
Override Thread.start() to handle the internal state semaphore.
source code
 
pause(self, pause)
Pause current internal timer countdown.
source code
None
set_delay(self, delay)
Change current delay in seconds.
source code
None
set_delay_before(self, delay_before)
Set whether delay before the execution of the function or not.
source code
None
set_accuracy(self, accuracy)
Set whether delay function must be accurate or not.
source code
 
run(self)
This method is called automatically when start() is called.
source code
 
kill(self)
Stop the execution of the timed function
source code

Inherited from threading.Thread: __repr__, getName, isAlive, isDaemon, is_alive, join, setDaemon, setName

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties

Inherited from threading.Thread: daemon, ident, name

Inherited from object: __class__

Method Details

__init__(self, delay, *args, **kwargs)
(Constructor)

source code 

TimeScheduled constructor.

Parameters:
  • delay (float) - delay in seconds between a function call and another.
  • *args - function as first magic arg and its arguments
  • *kwargs - keyword arguments of the function passed
Returns: None
None
Overrides: object.__init__

start(self)

source code 

Override Thread.start() to handle the internal state semaphore.

Overrides: threading.Thread.start

pause(self, pause)

source code 

Pause current internal timer countdown.

Parameters:
  • pause (bool) - True to pause timer

set_delay(self, delay)

source code 

Change current delay in seconds.

Parameters:
  • delay (float) - new delay
Returns: None
None

set_delay_before(self, delay_before)

source code 

Set whether delay before the execution of the function or not.

Parameters:
  • delay_before (bool) - delay before boolean
Returns: None
None

set_accuracy(self, accuracy)

source code 

Set whether delay function must be accurate or not.

Parameters:
  • accuracy (bool) - accuracy boolean
Returns: None
None

run(self)

source code 

This method is called automatically when start() is called. Don't call this directly!!!

Overrides: threading.Thread.run