def _updateProtocol(self, prot): prot2 = getProtocolFromDb(prot.getProject().path, prot.getDbPath(), prot.getObjId()) # Close DB connections prot2.getProject().closeMapper() prot2.closeMappers() return prot2
def _loadProt(): # Load the last version of the protocol from its own database loadedProt = getProtocolFromDb(prot.getProject().path, prot.getDbPath(), prot.getObjId()) # Close DB connections loadedProt.getProject().closeMapper() loadedProt.closeMappers() return loadedProt
def _getUpdatedProtocol(self): prot = self.protocol prot2 = getProtocolFromDb(self.protocol.getProject().path, prot.getDbPath(), prot.getObjId()) # Close DB connections prot2.getProject().closeMapper() prot2.closeMappers() return prot2
def _updateProtocol(self, protocol): """ Retrieve the updated protocol """ prot2 = getProtocolFromDb(protocol.getProject().path, protocol.getDbPath(), protocol.getObjId()) # Close DB connections prot2.closeMappers() return prot2
def getUpdatedProtocol(protocol): """ Retrieve the updated protocol and close db connections """ prot2 = getProtocolFromDb(os.getcwd(), protocol.getDbPath(), protocol.getObjId()) # Close DB connections prot2.getProject().closeMapper() prot2.closeMappers() return prot2
def _loadProt(): # Load the last version of the protocol from its own database prot2 = getProtocolFromDb(prot.getProject().path, prot.getDbPath(), prot.getObjId()) # Close DB connections prot2.getProject().closeMapper() prot2.closeMappers() return prot2
def updateProtocol(cls, prot): """ Method used for streaming when we need to update the protocol to check if there are new outputs. """ prot2 = getProtocolFromDb(prot.getProject().path, prot.getDbPath(), prot.getObjId()) # Close DB connections prot2.getProject().closeMapper() prot2.closeMappers() return prot2
def _updateProtocol(self, protocol, tries=0, checkPid=False): # If this is read only exit if self.isReadOnly(): return # If we are already updated, comparing timestamps if pwprot.isProtocolUpToDate(protocol): return try: # Backup the values of 'jobId', 'label' and 'comment' # to be restored after the .copy jobId = protocol.getJobId() label = protocol.getObjLabel() comment = protocol.getObjComment() # If the protocol database has .... # Comparing date will not work unless we have a reliable # lastModificationDate of a protocol in the project.sqlite # TODO: when launching remote protocols, the db should be # TODO: retrieved in a different way. prot2 = pwprot.getProtocolFromDb(self.path, protocol.getDbPath(), protocol.getObjId()) if checkPid: self.checkPid(prot2) # Copy is only working for db restored objects protocol.setMapper(self.mapper) protocol.copy(prot2, copyId=False) # Restore backup values protocol.setJobId(jobId) protocol.setObjLabel(label) protocol.setObjComment(comment) protocol.lastUpdateTimeStamp.set(datetime.datetime.now()) self.mapper.store(protocol) # Close DB connections prot2.getProject().closeMapper() prot2.closeMappers() except Exception, ex: print("Error trying to update protocol: %s(jobId=%s)\n " "ERROR: %s, tries=%d" % (protocol.getObjName(), jobId, ex, tries)) if tries == 3: # 3 tries have been failed traceback.print_exc() # If any problem happens, the protocol will be marked # with a FAILED status protocol.setFailed(str(ex)) self.mapper.store(protocol) else: time.sleep(0.5) self._updateProtocol(protocol, tries + 1)
def _updateProtocol(self, protocol, tries=0): if not self.isReadOnly(): try: # Backup the values of 'jobId', 'label' and 'comment' # to be restored after the .copy jobId = protocol.getJobId() label = protocol.getObjLabel() comment = protocol.getObjComment() # TODO: when launching remote protocols, the db should be retrieved # in a different way. # join(protocol.getHostConfig().getHostPath(), protocol.getDbPath()) prot2 = pwprot.getProtocolFromDb(self.path, protocol.getDbPath(), protocol.getObjId()) # Copy is only working for db restored objects protocol.setMapper(self.mapper) protocol.copy(prot2, copyId=False) # Restore backup values protocol.setJobId(jobId) protocol.setObjLabel(label) protocol.setObjComment(comment) self.mapper.store(protocol) # Close DB connections prot2.getProject().closeMapper() prot2.closeMappers() except Exception, ex: print "Error trying to update protocol: %s(jobId=%s)\n ERROR: %s, tries=%d" % ( protocol.getObjName(), jobId, ex, tries) if tries == 3: # 3 tries have been failed traceback.print_exc() # If any problem happens, the protocol will be marked with a status fail protocol.setFailed(str(ex)) self.mapper.store(protocol) else: time.sleep(0.5) self._updateProtocol(protocol, tries + 1)
mode = sys.argv[1] if mode not in ['run', 'stop']: usage("Mode should be 'run' or 'stop'. Received: '%s'" % mode) projectPath = os.path.join(os.environ['SCIPION_USER_DATA'], 'projects', sys.argv[2]) print "projectPath: ", projectPath protDbPath = sys.argv[3] protId = int(sys.argv[4]) from pyworkflow.protocol import getProtocolFromDb from pyworkflow.protocol.launch import launch, stop protocol = getProtocolFromDb(projectPath, protDbPath, protId, chdir=False) # We need to change the hostname to localhost, since it will # be considered 'local' from now on to either run or stop protocol.setHostName('localhost') if mode == 'run': FNULL = open(os.devnull, 'w') jobId = launch(protocol, stdin=None, stdout=FNULL, stderr=subprocess.STDOUT) print "Scipion remote jobid: %d" % jobId elif mode == 'stop': stop(protocol) else: usage()
usage("Received only %d arguments" % n) mode = sys.argv[1] if mode not in ['run', 'stop']: usage("Mode should be 'run' or 'stop'. Received: '%s'" % mode) projectPath = os.path.join(os.environ['SCIPION_USER_DATA'], 'projects', sys.argv[2]) print "projectPath: ", projectPath protDbPath = sys.argv[3] protId = int(sys.argv[4]) from pyworkflow.protocol import getProtocolFromDb from pyworkflow.protocol.launch import launch, stop protocol = getProtocolFromDb(projectPath, protDbPath, protId, chdir=False) # We need to change the hostname to localhost, since it will # be considered 'local' from now on to either run or stop protocol.setHostName('localhost') if mode == 'run': FNULL = open(os.devnull, 'w') jobId = launch(protocol, stdin=None, stdout=FNULL, stderr=subprocess.STDOUT) print "Scipion remote jobid: %d" % jobId elif mode == 'stop': stop(protocol) else: usage()
def _loadProtocol(self): return getProtocolFromDb(self._args.projPath, self._args.dbPath, self._args.protId, chdir=True)
try: from rpdb2 import start_embedded_debugger from signal import signal, SIGUSR2 signal(SIGUSR2, lambda sig, frame: start_embedded_debugger('a')) except ImportError: pass if __name__ == '__main__': if len(sys.argv) > 2: projPath = sys.argv[1] dbPath = sys.argv[2] protId = int(sys.argv[3]) from pyworkflow.protocol import runProtocolMain, getProtocolFromDb # Enter to the project directory and load protocol from db protocol = getProtocolFromDb(projPath, dbPath, protId, chdir=True) mapper = protocol.getMapper() log = open(protocol._getLogsPath('schedule.log'), 'w') pid = os.getpid() protocol.setPid(pid) def _log(msg): print >> log, "%s: %s" % (pwutils.prettyTimestamp(), msg) log.flush() _log("Scheduling protocol %s, pid: %s" % (protId, pid)) mapper.store(protocol) mapper.commit() mapper.close()