ChangeSet 1.1456, 2005/05/18 19:08:47+01:00, cl349@xxxxxxxxxxxxxxxxxxxx
XendDomain.py, scheduler.py:
Simplify scheduler.
Signed-off-by: Christian Limpach <Christian.Limpach@xxxxxxxxxxxx>
XendDomain.py | 9 +++------
scheduler.py | 43 +++++++++++++++++++------------------------
2 files changed, 22 insertions(+), 30 deletions(-)
diff -Nru a/tools/python/xen/xend/XendDomain.py
b/tools/python/xen/xend/XendDomain.py
--- a/tools/python/xen/xend/XendDomain.py 2005-05-18 15:02:23 -04:00
+++ b/tools/python/xen/xend/XendDomain.py 2005-05-18 15:02:23 -04:00
@@ -19,7 +19,7 @@
from XendError import XendError
from XendLogging import log
-from scheduler import Scheduler
+import scheduler
from xen.xend.server import channel
@@ -83,9 +83,6 @@
"""Table of pending domain shutdowns, indexed by domain id."""
shutdowns_by_id = {}
- """Table of delayed calls."""
- scheduler = Scheduler()
-
def __init__(self):
# Hack alert. Python does not support mutual imports, but
XendDomainInfo
# needs access to the XendDomain instance to look up domains.
Attempting
@@ -290,7 +287,7 @@
else:
self._delete_domain(d.id)
if cleanup and do_domain_restarts:
- self.scheduler.now(self.domain_restarts)
+ scheduler.now(self.domain_restarts)
def update_domain(self, id):
"""Update the saved info for a domain.
@@ -506,7 +503,7 @@
timeout = min(timeout, shutdown.getTimeout())
if self.shutdowns_by_id:
# Pending shutdowns remain - reschedule.
- self.scheduler.later(timeout, self.domain_shutdowns)
+ scheduler.later(timeout, self.domain_shutdowns)
def domain_restart_schedule(self, id, reason, force=False):
"""Schedule a restart for a domain if it needs one.
diff -Nru a/tools/python/xen/xend/scheduler.py
b/tools/python/xen/xend/scheduler.py
--- a/tools/python/xen/xend/scheduler.py 2005-05-18 15:02:23 -04:00
+++ b/tools/python/xen/xend/scheduler.py 2005-05-18 15:02:23 -04:00
@@ -1,29 +1,24 @@
import threading
-class Scheduler:
+def later(delay, fn, args=(), kwargs={}):
+ """Schedule a function to be called later.
- def later(self, _delay, _fn, args=(), kwargs={}):
- """Schedule a function to be called later.
+ @param _delay: delay in seconds
+ @param _fn: function
+ @param args: arguments (list)
+ @param kwargs keyword arguments (map)
+ """
+ timer = threading.Timer(delay, fn, args=args, kwargs=kwargs)
+ timer.start()
+ return timer
- @param _delay: delay in seconds
- @param _fn: function
- @param args: arguments (list)
- @param kwargs keyword arguments (map)
- """
- runargs = [ _fn, args, kwargs ]
- timer = threading.Timer(_delay, self._run, args=runargs)
- timer.start()
+def now(fn, args=(), kwargs={}):
+ """Schedule a function to be called now.
- def now(self, _fn, args=(), kwargs={}):
- """Schedule a function to be called now.
-
- @param _fn: function
- @param args: arguments (list)
- @param kwargs keyword arguments (map)
- """
- runargs = [ _fn, args, kwargs ]
- thread = threading.Thread(target=self._run, args=runargs)
- thread.start()
-
- def _run(self, fn, args, kwargs):
- fn(*args, **kwargs)
+ @param _fn: function
+ @param args: arguments (list)
+ @param kwargs keyword arguments (map)
+ """
+ thread = threading.Thread(target=fn, args=args, kwargs=kwargs)
+ thread.start()
+ return thread
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|