Skip to content

Commit 0516998

Browse files
committed
Use itertools.count for the session counter
1 parent 90461c3 commit 0516998

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

unpythonic/net/server.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@
125125
import socketserver
126126
import atexit
127127
from textwrap import dedent
128+
from itertools import count
128129

129130
try:
130131
# macro-enabled console with imacropy semantics
@@ -155,7 +156,7 @@
155156

156157
_server_instance = None
157158
_active_sessions = {}
158-
_session_counter = 0 # for generating session ids, needed for pairing control and REPL sessions.
159+
_session_counter = count(start=1) # for generating session ids, needed for pairing control and REPL sessions.
159160
_halt_pending = False
160161
_original_stdin = sys.stdin
161162
_original_stdout = sys.stdout
@@ -357,9 +358,7 @@ def handle(self):
357358

358359
try:
359360
# for control/REPL pairing
360-
global _session_counter
361-
_session_counter += 1
362-
self.session_id = _session_counter
361+
self.session_id = next(_session_counter)
363362
_active_sessions[self.session_id] = self # also for exit monitoring
364363

365364
# self.request is the socket. We don't need a StreamRequestHandler with self.rfile and self.wfile,

0 commit comments

Comments
 (0)