Esempio n. 1
0
def run(host, port, seed) :
  smds.initialize(False, seed=seed)

  # Connect to parent
  parent.connect((host,port))

  while (True) :
    mx.acquire()
    (r,w,e) = select([parent],[],[],0)
    if len(r) :
      packet = smds.recvMsg(parent)
      if not packet :
        mx.release()
        parent.close()
        smds.shutdown()
        exit("Error reading from parent.")
      (msg, args) = packet
      if (msg > maxHandler) :
        h = nullHandler
        args = (msg,)+args
      else : h = handlers[msg]
      h(*args)
    checkTime()
    mx.release()
    sleep(1)
Esempio n. 2
0
def releaseWork(etoc) :
  r = smds.Engine.releaseWork(etoc)
  if r > 0 :
    if not smds.sendMsg(parent, smds.messages['RELEASE'], r) :
      mx.release()
      smds.msg("Error writing to master.")
      parent.close()
      smds.shutdown()
      exit()
Esempio n. 3
0
def returnTask(t, worktag) :
  mx.acquire()
  try : smds.sendMsg(parent, smds.messages['WORK'], worktag, t.strip(True))
  except :
    mx.release()
    smds.msg("Error sending work to master.")
    parent.close()
    smds.shutdown()
    exit()
  else :
    mx.release()
  return None
Esempio n. 4
0
def checkTime() :
  global lastEtoc
  etoc = smds.Engine.etoc() - time()
  if etoc <= 0 and lastEtoc > 0 :
    lastEtoc = 0
    return
  if etoc > 0 and abs(smds.Engine.etoc()-lastEtoc) > 90.0 :
    smds.msg("Notifying master of etoc %f" % etoc, smds.MSG_DBUG)
    if not smds.sendMsg(parent, smds.messages['ETOC'], 
					etoc, smds.Engine.rate()) :
      mx.release()
      smds.msg("Error writing to master.", smds.MSG_WARN)
      parent.close()
      smds.shutdown()
      exit()
    lastEtoc = smds.Engine.etoc()
Esempio n. 5
0
def quit():
  mx.release()
  smds.msg("Quit!")
  parent.close()
  smds.shutdown()
  exit()