2 # -----------------------------------------------------------------------
3 # Copyright (C) 2007-2008 King County Library System
4 # Bill Erickson <erickson@esilibrary.com>
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 3
9 # of the License, or (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 # -----------------------------------------------------------------------
19 from script import ScriptThread
20 from threading import local
26 """ A Task represents a single unit of work. They are created
27 before thread allocation, so no state information is stored
28 on the actual Task object.
31 def __init__(self, name=''):
40 def run(self, **kwargs):
41 """Override this method with the work to perform"""
42 logError('Override me!')
44 def start(self, **kwargs):
47 ret = None # capture the return value from the task
51 ret = self.run(**kwargs)
52 self.duration = time.time() - start
57 sys.stderr.write(str(E))
58 # store the error info somewhere?
60 logDebug('%s: thread = %d : duration = %f' % (
61 self.name, ScriptThread.getThreadID(), self.duration))
64 dbConn = ScriptThread.currentScriptThread().dbConnection
65 dbConn.insertTask(self)