def main(self): (self.options, self.args) = self.parser.parse_args() GrinderLog.setup(self.options.debug) self.args = self.args[1:] # do the work, catch most common errors here: self._do_command()
#Note: We want to explicitly kill the child activeobject # so will use abort() on activeobject's Method class self.fetcher.dummy_method.abort() # We were seeing the invocation of __del__() on activeobject # being delayed, hence child processes weren't dying when they should. # therefore we added the explicit abort() del self.fetcher except Exception, e: LOG.error("%s" % (traceback.format_exc())) finally: self.fetcher_lock.release() LOG.info("Thread ending") if __name__ == "__main__": from grinder import GrinderLog GrinderLog.setup(True) # This a very basic test just to feel out the flow of the threads # pulling items from a shared Queue and exiting cleanly # Create a simple fetcher that sleeps every few items class SimpleFetcher(object): def fetchItem(self, x): print "Working on item %s" % (x) if x % 3 == 0: print "Sleeping 1 second" time.sleep(1) return BaseFetch.STATUS_NOOP pf = ParallelFetch(SimpleFetcher(), 3) numPkgs = 20 pkgs = range(0, numPkgs) pf.addItemList(pkgs)
return False return True def curlifyHeaders(headers): # pycurl drops empty header. Combining headers cheaders = "" for key,value in headers.items(): cheaders += key +": "+ str(value) + "\r\n" return [cheaders] if __name__ == "__main__": from grinder import GrinderLog GrinderLog.setup(True) systemId = open("/etc/sysconfig/rhn/systemid").read() baseURL = "http://satellite.rhn.redhat.com" bf = BaseFetch() itemInfo = {} fileName = "Virtualization-es-ES-5.2-9.noarch.rpm" fetchName = "Virtualization-es-ES-5.2-9:.noarch.rpm" channelLabel = "rhel-i386-server-vt-5" fetchURL = baseURL + "/SAT/$RHN/" + channelLabel + "/getPackage/" + fetchName; itemSize = "1731195" md5sum = "91b0f20aeeda88ddae4959797003a173" hashtype = "md5" savePath = "./test123" from RHNComm import RHNComm rhnComm = RHNComm(baseURL, systemId) authMap = rhnComm.login()
def __init__(self, arg): unittest.TestCase.__init__(self,arg) GrinderLog.setup(False)