def run(self): comm = Communicator(self.port) try: comm.bind() self.response = comm.acceptObject() except SocketOpenError, error: sys.stderr.write("%d\n%s\n%s\n" % (self.port, traceback(error), error))
def insert_refs(self, widget, data=None): refs = self.table.getSelected() comm = Communicator(self.REF_LISTEN_PORT) nfailed = 0 sent = False try: comm.sendObject(refs) comm.close() sent = True except Exception, error: pass
def run(self, obj): answer = self.answer_t() comm = Communicator(self.request_port) try: comm.open() answer.start() time.sleep(1) comm.sendObject(obj) except SocketOpenError, error: sys.stderr.write("%d\n%s\n%s\n" % (self.request_port, traceback(error), error)) self.close_answer(answer) return #thread is already dead
def __init__(self, citation): self.citation = citation self.stopthread = threading.Event() self.server = Communicator(CiteManager.REF_LISTEN_PORT) self.server.bind() threading.Thread.__init__(self)
def write(self, text): try: comm = Communicator(gtkserver.REQUEST_PORT) comm.open() comm.sendObject(text) comm.close() except: pass
def close_answer(self, answer): try: comm = Communicator(answer.port) comm.open() comm.sendObject("die!") comm.close() except Exception, error: sys.stderr.write("%d\n%s\n%s\n" % (self.request_port, traceback(error), error))
class CiteThread(threading.Thread): def __init__(self, citation): self.citation = citation self.stopthread = threading.Event() self.server = Communicator(CiteManager.REF_LISTEN_PORT) self.server.bind() threading.Thread.__init__(self) def run(self): while not self.stopthread.isSet(): try: objlist = self.server.acceptObject() if objlist: # if we got a list of objects self.citation.addReferences(objlist) except Exception, exc: pass self.server.close()
class Server: def __init__(self, request_port, answer_port = None): self.answer_port = answer_port self.request_port = request_port self.server = Communicator(self.request_port) self.server.bind() self.bib = Bibliography() def report(self): from pygui.gtkserver import report report() def run(self): while 1: ret = "" try: obj = self.server.acceptObject() if isinstance(obj, ServerStop): #end self.stop() return ret = self.process(obj) except SocketDie: return except Exception, error: sys.stderr.write("%s\n%s\n" % (traceback(error), error)) try: if self.answer_port: comm = Communicator(self.answer_port) comm.open() comm.sendObject(ret) comm.close() except SocketOpenError, error: sys.stderr.write("%d\n%s\n%s\n" % (self.answer_port, traceback(error), error)) except Exception, error: sys.stderr.write("%s\n%s\n" % (traceback(error), error))
def display_report(cls): try: import inspect frame = inspect.currentframe().f_back.f_back.f_back info = inspect.getframeinfo(frame) framestr = "%s" % str(info) comm = Communicator(cls.port) comm.open() comm.sendObject(framestr) comm.close() except Exception, error: sys.stderr.write("%s\n" % error)
def run(self): while 1: ret = "" try: obj = self.server.acceptObject() if isinstance(obj, ServerStop): #end self.stop() return ret = self.process(obj) except SocketDie: return except Exception, error: sys.stderr.write("%s\n%s\n" % (traceback(error), error)) try: if self.answer_port: comm = Communicator(self.answer_port) comm.open() comm.sendObject(ret) comm.close() except SocketOpenError, error: sys.stderr.write("%d\n%s\n%s\n" % (self.answer_port, traceback(error), error))
def stop(self): self.stopthread.set() comm = Communicator(CiteManager.REF_LISTEN_PORT) comm.sendObject([]) # send blank array to bring down thread
def __init__(self, request_port, answer_port = None): self.answer_port = answer_port self.request_port = request_port self.server = Communicator(self.request_port) self.server.bind() self.bib = Bibliography()
def stop(self): comm = Communicator(self.server.request_port) comm.open() comm.sendObject(ServerStop()) comm.close() self.thr.join()