Permalink
Browse files

Now I'm adding back the old BackgroundFunction and renaming the previ…

…ous BackgroundFunction to ProcessFunction
  • Loading branch information...
1 parent 3650ec5 commit f245be61f768d492c634bf668a2079a91c04368c Jason Baker committed Aug 11, 2010
Showing with 21 additions and 7 deletions.
  1. +20 −6 shrapnel/classtools.py
  2. +1 −1 shrapnel/command.py
View
@@ -32,17 +32,14 @@ def __new__(cls, *args, **kwargs):
def _call_from_new(cls, instance, args, kwargs):
result = None
if isinstance(instance, cls):
+ instance.__init__(*args, **kwargs)
result = instance()
if isinstance(result, cls):
raise RuntimeError("{0.__name__}.__call__ cannot return an instance of {0.__name__}, otherwise the __new__ mechanism would call __init__ twice.".format(cls))
return result
- def __init__(self, **kwargs):
- object.__init__(self)
- self.__dict__.update(kwargs)
-
def __call__(self):
pass
@@ -57,10 +54,9 @@ def run_background_func(cls, args, kwargs):
import traceback
traceback.print_exc()
-class BackgroundFunction(UserFunction):
+class ProcessFunction(UserFunction):
_procpool = None
def __init__(self, callback=None, **kwargs):
- print self.__dict__
self.callback = callback
UserFunction.__init__(self, **kwargs)
@@ -99,3 +95,21 @@ def __call__(self):
def execute(self):
pass
+
+class BackgroundFunction(UserFunction):
+ def __init__(self, callback = None):
+ super(BackgroundFunction, self).__init__()
+ self.callback = callback
+
+ def __call__(self):
+ if self.callback:
+ import web
+ target = web.flagger(self.execute, self.callback)
+ else:
+ target = self.execute
+
+ threading.Thread(target = target).start()
+
+ def execute(self):
+ pass
+
View
@@ -33,7 +33,7 @@ def __init__(self, path, version = '', command = None):
self.command = command or self.serve
def run(self):
- shrapnel.classtools.BackgroundFunction.procpool
+ shrapnel.classtools.ProcessFunction.procpool
parser = optparse.OptionParser(
usage = "usage: %prog [options]",
version = "%%prog %s" % (self.version,),

0 comments on commit f245be6

Please sign in to comment.