LegacyTaskRunner¶
- class lsst.pipe.base.LegacyTaskRunner(TaskClass, parsedCmd, doReturnResults=False)¶
- Bases: - TaskRunner- A - TaskRunnerfor- CmdLineTasks which calls the- Task‘s- runmethod on a- dataRefrather than the- runDataRefmethod.- Attributes Summary - Default timeout (seconds) for multiprocessing. - Methods Summary - __call__(args)- Run the Task on a single target. - getTargetList(parsedCmd, **kwargs)- Get a list of (dataRef, kwargs) for - TaskRunner.__call__.- makeTask([parsedCmd, args])- Create a Task instance. - precall(parsedCmd)- Hook for code that should run exactly once, before multiprocessing. - Prepare this instance for multiprocessing - run(parsedCmd)- Run the task on all targets. - runTask(task, dataRef, kwargs)- Call - runfor this task instead of- runDataRef.- Attributes Documentation - TIMEOUT = 2592000¶
- Default timeout (seconds) for multiprocessing. 
 - Methods Documentation - __call__(args)¶
- Run the Task on a single target. - Parameters:
- args
- Arguments for Task.runDataRef() 
 
- Returns:
- structlsst.pipe.base.Struct
- Contains these fields if - doReturnResultsis- True:- dataRef: the provided data reference.
- metadata: task metadata after execution of run.
- result: result returned by task run, or- Noneif the task fails.
- exitStatus: 0 if the task completed successfully, 1 otherwise.
 - If - doReturnResultsis- Falsethe struct contains:- exitStatus: 0 if the task completed successfully, 1 otherwise.
 
 
- struct
 - Notes - This default implementation assumes that the - argsis a tuple containing a data reference and a dict of keyword arguments.- Warning - If you override this method and wish to return something when - doReturnResultsis- False, then it must be picklable to support multiprocessing and it should be small enough that pickling and unpickling do not add excessive overhead.
 - static getTargetList(parsedCmd, **kwargs)¶
- Get a list of (dataRef, kwargs) for - TaskRunner.__call__.- Parameters:
- parsedCmdargparse.Namespace
- The parsed command object returned by - lsst.pipe.base.ArgumentParser.parse_args.
- kwargs
- Any additional keyword arguments. In the default - TaskRunnerthis is an empty dict, but having it simplifies overriding- TaskRunnerfor tasks whose runDataRef method takes additional arguments (see case (1) below).
 
- parsedCmd
 - Notes - The default implementation of - TaskRunner.getTargetListand- TaskRunner.__call__works for any command-line task whose- runDataRefmethod takes exactly one argument: a data reference. Otherwise you must provide a variant of TaskRunner that overrides- TaskRunner.getTargetListand possibly- TaskRunner.__call__. There are two cases.- Case 1 - If your command-line task has a - runDataRefmethod that takes one data reference followed by additional arguments, then you need only override- TaskRunner.getTargetListto return the additional arguments as an argument dict. To make this easier, your overridden version of- getTargetListmay call- TaskRunner.getTargetListwith the extra arguments as keyword arguments. For example, the following adds an argument dict containing a single key: “calExpList”, whose value is the list of data IDs for the calexp ID argument:- def getTargetList(parsedCmd): return TaskRunner.getTargetList( parsedCmd, calExpList=parsedCmd.calexp.idList ) - It is equivalent to this slightly longer version: - @staticmethod def getTargetList(parsedCmd): argDict = dict(calExpList=parsedCmd.calexp.idList) return [(dataId, argDict) for dataId in parsedCmd.id.idList] - Case 2 - If your task does not meet condition (1) then you must override both TaskRunner.getTargetList and - TaskRunner.__call__. You may do this however you see fit, so long as- TaskRunner.getTargetListreturns a list, each of whose elements is sent to- TaskRunner.__call__, which runs your task.
 - makeTask(parsedCmd=None, args=None)¶
- Create a Task instance. - Parameters:
- parsedCmd
- Parsed command-line options (used for extra task args by some task runners). 
- args
- Args tuple passed to - TaskRunner.__call__(used for extra task arguments by some task runners).
 
 - Notes - makeTaskcan be called with either the- parsedCmdargument or- argsargument set to None, but it must construct identical Task instances in either case.- Subclasses may ignore this method entirely if they reimplement both - TaskRunner.precalland- TaskRunner.__call__.
 - precall(parsedCmd)¶
- Hook for code that should run exactly once, before multiprocessing. - Notes - Must return True if - TaskRunner.__call__should subsequently be called.- Warning - Implementations must take care to ensure that no unpicklable attributes are added to the TaskRunner itself, for compatibility with multiprocessing. - The default implementation writes package versions, schemas and configs, or compares them to existing files on disk if present. 
 - prepareForMultiProcessing()¶
- Prepare this instance for multiprocessing - Optional non-picklable elements are removed. - This is only called if the task is run under multiprocessing. 
 - run(parsedCmd)¶
- Run the task on all targets. - Parameters:
- parsedCmdargparse.Namespace
- Parsed command - argparse.Namespace.
 
- parsedCmd
- Returns:
- resultListlist
- A list of results returned by - TaskRunner.__call__, or an empty list if- TaskRunner.__call__is not called (e.g. if- TaskRunner.precallreturns- False). See- TaskRunner.__call__for details.
 
- resultList
 - Notes - The task is run under multiprocessing if - TaskRunner.numProcessesis more than 1; otherwise processing is serial.
 - runTask(task, dataRef, kwargs)¶
- Call - runfor this task instead of- runDataRef. See- TaskRunner.runTaskabove for details.