Package schrodinger :: Package job :: Module queue :: Class ThreadedJob
[hide private]
[frames] | no frames]

Class ThreadedJob

object --+    
         |    
   BaseJob --+
             |
            ThreadedJob

This class is for jobs that don't run under job control yet can have significant computational requirements in the python part of the JobDJ process. For code run in separate processes, see the SubprocessJob class.

A ThreadedJob instance is run in a separate thread and so won't hold up execution of the main thread running the JobDJ instance. This allows additional jobs to be started and monitored even while the thread computation is ongoing.

Due to the Global Interpreter Lock and the fact that we don't release it in any of our SWIG wrappers, only one ThreadedJob will actually be run at a time.

Note that the directory in which the command will be executed can't be guaranteed for a job run in a separate thread. Even if an explicit os.chdir is invoked in the doCommand implementation, control may switch to the main thread and the directory could change before the subsequent statement is executed. So, all I/O must be done on absolute paths.

Instance Methods [hide private]
 
__init__(self)
x.__init__(...) initializes x; see help(type(x)) for signature
 
__getstate__(self)
 
__setstate__(self, state_dict)
Reset state from a pickle.
 
getCommandDir(self)
Override the base getCommandDir method and always return None so that no attempt is made to run in a separate subdirectory.
 
update(self)
Update the current job status.
 
processResults(self)
This method is a hook for subclasses.
 
hasUnprocessedResults(self)
This method is a hook for subclasses.
 
run(self, *args, **kwargs)
Run the command in a separate thread.
 
kill(self)
This method set termination request for threaded job.

Inherited from BaseJob: __lt__, addFinalizer, addGroupPrereq, addPrereq, doCommand, finalize, genAllJobs, genAllPrereqs, getJobDJ, getPrereqs, getStatusStrings, hasStarted, isComplete, maxFailuresReached, postCommand, preCommand, runsLocally, setup

Inherited from BaseJob (private): _getState, _pruneGraph, _setState

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables [hide private]

Inherited from BaseJob: init_count

Properties [hide private]

Inherited from BaseJob: state

Inherited from object: __class__

Method Details [hide private]

__init__(self)
(Constructor)

 

x.__init__(...) initializes x; see help(type(x)) for signature

Parameters:
  • command_dir - The directory from which to run the command.
Overrides: object.__init__
(inherited documentation)

getCommandDir(self)

 

Override the base getCommandDir method and always return None so that no attempt is made to run in a separate subdirectory.

Don't override this method in subclasses and don't use os.chdir in your doCommand implementation.

Overrides: BaseJob.getCommandDir

update(self)

 

Update the current job status.

Overrides: BaseJob.update

processResults(self)

 

This method is a hook for subclasses.

It is called from the update method and operates in the main thread. Therefore, it can be used to interact with the parent JobDJ instance, for example adding new jobs.

All communication with the compute thread should be done via thread-safe mechanisms such as Queue.Queue.

hasUnprocessedResults(self)

 

This method is a hook for subclasses.

It's possible the thread will be finished but the processing of results is not yet complete. Returning True here will keep the job alive and the update method will continue to be called periodically.

run(self, *args, **kwargs)

 

Run the command in a separate thread.

Overrides: BaseJob.run

kill(self)

 

This method set termination request for threaded job.

After 60s, the threaded job is marked as done if it is still alive.