Skip to content

Commit 6824b92

Browse files
committed
adjust appearance on async mode
1 parent 929b40b commit 6824b92

File tree

3 files changed

+26
-18
lines changed

3 files changed

+26
-18
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
myconf
2+
test.conf

deadman

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import signal
1919
import argparse
2020
import asyncio
2121
import concurrent.futures
22-
from shlex import quote
2322
from subprocess import DEVNULL, PIPE, getoutput
2423
import _thread
2524

@@ -64,7 +63,6 @@ PING_SSH_FAILED = -3
6463

6564
LOGDIR = ""
6665

67-
6866
class 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

179177
class 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):

deadman.conf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
googleDNS 8.8.8.8
55
quad9 9.9.9.9
66
mroot 202.12.27.33
7-
test-fail 192.168.255.254
87
mroot6 2001:dc3::35
98
kame 203.178.141.194
109
kame6 2001:200:dff:fff1:216:3eff:feb1:44d7

0 commit comments

Comments
 (0)