class Work(): def __init__(self, bitHopper): self.bitHopper = bitHopper self.i = 0 try: self.agent = twisted.web.client.Agent(bitHopper.reactor, connectTimeout=5) except: self.agent = twisted.web.client.Agent(bitHopper.reactor) self.lp_agent = Agent(bitHopper.reactor, persistent=True) @defer.inlineCallbacks def jsonrpc_lpcall(self, server, url, lp): try: self.i += 1 request = json.dumps({'method':'getwork', 'params':[], 'id':self.i}, ensure_ascii = True) pool = self.bitHopper.pool.servers[server] header = {'Authorization':["Basic " +base64.b64encode(pool['user']+ ":" + pool['pass'])], 'User-Agent': ['poclbm/20110709'], 'Content-Type': ['application/json'] } d = self.lp_agent.request('GET', url, Headers(header), StringProducer(request)) body = yield d if body == None: lp.receive(None, server) defer.returnValue(None) finish = Deferred() body.deliverBody(WorkProtocol(finish)) text = yield finish lp.receive(text, server) defer.returnValue(None) except Exception, e: self.bitHopper.log_dbg('Error in lpcall work.py') self.bitHopper.log_dbg(e) #traceback.print_exc() #print e.reasons[0] lp.receive(None, server) defer.returnValue(None)