ia64/xen-unstable

view tools/python/xen/xend/scheduler.py @ 6538:84ee014ebd41

Merge xen-vtx-unstable.hg
author adsharma@los-vmm.sc.intel.com
date Wed Aug 17 12:34:38 2005 -0800 (2005-08-17)
parents 23979fb12c49 f40c6650152e
children 99914b54f7bf
line source
1 #============================================================================
2 # This library is free software; you can redistribute it and/or
3 # modify it under the terms of version 2.1 of the GNU Lesser General Public
4 # License as published by the Free Software Foundation.
5 #
6 # This library is distributed in the hope that it will be useful,
7 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9 # Lesser General Public License for more details.
10 #
11 # You should have received a copy of the GNU Lesser General Public
12 # License along with this library; if not, write to the Free Software
13 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14 #============================================================================
15 # Copyright (C) 2004, 2005 Mike Wray <mike.wray@hp.com>
16 #============================================================================
18 import threading
20 def later(delay, fn, args=(), kwargs={}):
21 """Schedule a function to be called later.
23 @param _delay: delay in seconds
24 @param _fn: function
25 @param args: arguments (list)
26 @param kwargs keyword arguments (map)
27 """
28 timer = threading.Timer(delay, fn, args=args, kwargs=kwargs)
29 timer.start()
30 return timer
32 def now(fn, args=(), kwargs={}):
33 """Schedule a function to be called now.
35 @param _fn: function
36 @param args: arguments (list)
37 @param kwargs keyword arguments (map)
38 """
39 thread = threading.Thread(target=fn, args=args, kwargs=kwargs)
40 thread.start()
41 return thread