def _runQuery(self, qstr, eater, chunkSize): print 'running query' conn = self.connect() curs = conn.cursor() try: curs.execute(qstr) print 'ran it!' if eater is not None: task.schedule(eater, curs.fetchmany(chunkSize)) result = None else: result = curs.fetchall() except: print 'oops!' conn.rollback() traceback.print_exc() raise return result
def send(self, data): """Schedule data to be written in a thread-safe manner""" # instead of doing self.transport.write(data), which is not # thread safe, we do: task.schedule(self.transport.write, data)
def makeData(self): self.transport.write("twistedzombies") # schedule this function to be called t = task.Task() t.addWork(self.makeData) task.schedule(t)