Skip to content

Commit 775d642

Browse files
author
Zhou Wei
committed
fix verbose failure in windows
1 parent dc0279c commit 775d642

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

pproxy/verbose.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import time, sys, asyncio, functools
22

33
b2s = lambda i: f'{i/2**30:.1f}G' if i>=2**30 else f'{i/2**20:.1f}M' if i>=2**20 else f'{i/1024:.1f}K'
4-
def all_stat(stats):
4+
5+
def all_stat_other(stats):
56
cmd = sys.stdin.readline()
7+
all_stat(stats)
8+
9+
def all_stat(stats):
610
if len(stats) <= 1:
711
print('no traffic')
812
return
@@ -52,8 +56,14 @@ def modstat(remote_ip, host_name, stats=args.stats):
5256
tostat = (stats[0], stats.setdefault(remote_ip, {}).setdefault(host_name_2, [0]*6))
5357
return lambda i: lambda s: [st.__setitem__(i, st[i] + s) for st in tostat]
5458
args.modstat = modstat
59+
def win_readline(handler):
60+
while True:
61+
line = sys.stdin.readline()
62+
handler()
5563
if args.v >= 2:
5664
asyncio.ensure_future(realtime_stat(args.stats[0]))
57-
loop.add_reader(sys.stdin, functools.partial(all_stat, args.stats))
58-
65+
if sys.platform != 'win32':
66+
loop.add_reader(sys.stdin, functools.partial(all_stat_other, args.stats))
67+
else:
68+
loop.run_in_executor(None, win_readline, functools.partial(all_stat, args.stats))
5969

0 commit comments

Comments
 (0)