def _sessionRequest(self, url, session, delayAmount, data=None, ajax=None): try: startTime = time() if delayAmount else None if ajax: oldAccept = session.headers['Accept'] session.headers.update({ 'Accept': 'application/json, text/javascript, */*; q=0.01', 'X-Requested-With': 'XMLHttpRequest' }) if data: r = session.post(url, data=data, timeout=8) else: r = session.get(url, timeout=8) if ajax: # Restore the session headers. session.headers['Accept'] = oldAccept del session.headers['X-Requested-With'] if delayAmount: elapsed = time() - startTime if elapsed < delayAmount and elapsed > 0.1: timeSleep(delayAmount - elapsed) return r except: return type('FailedResponse', (object, ), {'ok': False})
def RunAsyncAndPrint(executor, code, ioHandler, printFunction, silent = False, timeout = 0.1): ioHandler.Clear() ioHandler.InitCapture() executor.AsyncRun(code) while not executor.HasFinished(): ioHandler.Poll() if not silent: printFunction(ioHandler) ioHandler.Clear() if executor.HasFinished(): break timeSleep(.1) executor.Wait() ioHandler.EndCapture()
def RunAsyncAndPrint(executor, code, ioHandler, printFunction, displayFunction, silent = False, timeout = 0.1): ioHandler.Clear() ioHandler.InitCapture() executor.AsyncRun(code) while not executor.HasFinished(): ioHandler.Poll() if not silent: printFunction(ioHandler) ioHandler.Clear() if executor.HasFinished(): break timeSleep(.1) executor.Wait() ioHandler.EndCapture()
def Wait(self): while self.poller.is_running: timeSleep(.1)