Skip to content

Commit 82013cf

Browse files
committed
examples/bench: Fix linting errors
1 parent 2a4fab4 commit 82013cf

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

examples/bench/echoclient.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33

44

55
import argparse
6+
import concurrent.futures
7+
import socket
68
import time
79

8-
from concurrent.futures import ProcessPoolExecutor
9-
from socket import *
10-
1110

1211
if __name__ == '__main__':
1312
parser = argparse.ArgumentParser()
@@ -48,12 +47,12 @@ def run_test(n):
4847
n //= args.mpr
4948

5049
if unix:
51-
sock = socket(AF_UNIX, SOCK_STREAM)
50+
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
5251
else:
53-
sock = socket(AF_INET, SOCK_STREAM)
52+
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
5453

5554
try:
56-
sock.setsockopt(IPPROTO_TCP, TCP_NODELAY, 1)
55+
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
5756
except (OSError, NameError):
5857
pass
5958

@@ -73,10 +72,10 @@ def run_test(n):
7372
NMESSAGES = args.num
7473
start = time.time()
7574
for _ in range(TIMES):
76-
with ProcessPoolExecutor(max_workers=N) as e:
75+
with concurrent.futures.ProcessPoolExecutor(max_workers=N) as e:
7776
for _ in range(N):
7877
e.submit(run_test, NMESSAGES)
7978
end = time.time()
8079
duration = end-start
81-
print(NMESSAGES*N*TIMES,'in', duration)
82-
print(NMESSAGES*N*TIMES/duration, 'requests/sec')
80+
print(NMESSAGES * N * TIMES, 'in', duration)
81+
print(NMESSAGES * N * TIMES / duration, 'requests/sec')

examples/bench/echoserver.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,18 @@
22
import asyncio
33
import gc
44
import os.path
5-
import socket as socket_module
6-
7-
from socket import *
5+
import socket
86

97

108
PRINT = 0
119

1210

1311
async def echo_server(loop, address, unix):
1412
if unix:
15-
sock = socket(AF_UNIX, SOCK_STREAM)
13+
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
1614
else:
17-
sock = socket(AF_INET, SOCK_STREAM)
18-
sock.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
15+
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
16+
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
1917
sock.bind(address)
2018
sock.listen(5)
2119
sock.setblocking(False)
@@ -31,7 +29,7 @@ async def echo_server(loop, address, unix):
3129

3230
async def echo_client(loop, client):
3331
try:
34-
client.setsockopt(IPPROTO_TCP, TCP_NODELAY, 1)
32+
client.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
3533
except (OSError, NameError):
3634
pass
3735

@@ -48,7 +46,7 @@ async def echo_client(loop, client):
4846
async def echo_client_streams(reader, writer):
4947
sock = writer.get_extra_info('socket')
5048
try:
51-
sock.setsockopt(IPPROTO_TCP, TCP_NODELAY, 1)
49+
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
5250
except (OSError, NameError):
5351
pass
5452
if PRINT:

0 commit comments

Comments
 (0)