@@ -19,7 +19,6 @@ import signal
1919import argparse
2020import asyncio
2121import concurrent .futures
22- from shlex import quote
2322from subprocess import DEVNULL , PIPE , getoutput
2423import _thread
2524
@@ -64,7 +63,6 @@ PING_SSH_FAILED = -3
6463
6564LOGDIR = ""
6665
67-
6866class PingResult :
6967
7068 def __init__ (self , success = False , errcode = PING_FAILED ,
@@ -112,8 +110,8 @@ class PingTarget:
112110 asyncio .run (self .async_send ())
113111
114112 async def async_send (self ):
115- self .snt += 1
116113 res = await self .ping .async_send ()
114+ self .snt += 1
117115 self .consume_ping_result (res )
118116
119117 def consume_ping_result (self , res ):
@@ -178,7 +176,8 @@ class PingTarget:
178176
179177class Ping :
180178
181- def __init__ (self , addr , osname , timeout = 1 , relay = None , source = None ):
179+ def __init__ (self , addr , osname , timeout = 1.0 ,
180+ relay = None , source = None ):
182181
183182 self .addr = addr
184183 self .osname = osname
@@ -250,10 +249,14 @@ class Ping:
250249 stdout = PIPE )
251250
252251 try :
253- await asyncio .wait_for (proc .wait (), timeout = 1.0 )
252+ await asyncio .wait_for (proc .wait (), timeout = self . timeout )
254253 except asyncio .TimeoutError :
254+ pass
255+ try :
255256 proc .terminate ()
256- await proc .wait ()
257+ except ProcessLookupError :
258+ pass
259+ await proc .wait ()
257260
258261 (out , err ) = await proc .communicate ()
259262 result = out .decode ("utf-8" )
@@ -582,10 +585,8 @@ class Deadman:
582585 _thread .start_new_thread (self .curs .key_thread , tuple (self .targets ))
583586
584587 # print blank line
585- num = 0
586- for target in self .targets :
587- num += 1
588- self .curs .print_pingtarget (target , num )
588+ for idx , target in enumerate (self .targets , 1 ):
589+ self .curs .print_pingtarget (target , idx )
589590
590591 while True :
591592
@@ -613,6 +614,11 @@ class Deadman:
613614
614615 def async_main (self ):
615616
617+ #n = len(self.targets)
618+ #executor = concurrent.futures.ThreadPoolExecutor(max_workers = n)
619+ #loop = asyncio.get_event_loop()
620+ #loop.set_default_executor(executor)
621+
616622 _thread .start_new_thread (self .curs .key_thread , tuple (self .targets ))
617623
618624 # print blank line
@@ -627,20 +633,22 @@ class Deadman:
627633 self .curs .erase_reference ()
628634 self .curs .print_reference ()
629635
636+ for idx , target in enumerate (self .targets , 1 ):
637+ self .curs .print_arrow (idx )
638+
639+ start = time .time ()
630640 asyncio .run (self .async_ping_targets ())
631641
642+ elapsed = time .time () - start
643+ if elapsed < 1.0 :
644+ time .sleep (1 - elapsed )
645+
632646 for idx , target in enumerate (self .targets , 1 ):
633- if target .state :
634- self .curs .print_arrow (idx )
635647 self .curs .erase_pingtarget (idx )
636648 self .curs .print_pingtarget (target , idx )
637-
638- arrow_visible_time = 0.8
639- time .sleep (arrow_visible_time )
640- for idx in range (1 , len (self .targets ) + 1 ):
641649 self .curs .erase_arrow (idx )
642650
643- time .sleep (PING_ALLTARGET_INTERVAL - arrow_visible_time )
651+ time .sleep (PING_ALLTARGET_INTERVAL )
644652
645653
646654 def refresh_window (self , signum , frame ):
0 commit comments