Skip to content

Commit 0feed3b

Browse files
committed
[interactive] Replace set_pipe_size by Popen(pipesize=...), because we now require Py3.10
1 parent 894466d commit 0feed3b

File tree

1 file changed

+4
-20
lines changed

1 file changed

+4
-20
lines changed

bin/interactive.py

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -186,15 +186,6 @@ def get_validator_command():
186186
# - Close remaining program + write end of pipe
187187
# - Close remaining read end of pipes
188188

189-
def set_pipe_size(pipe):
190-
# Somehow, setting the pipe buffer size is necessary to avoid hanging in larger interactions.
191-
# Note that this is equivalent to Popen's `pipesize` argument in Python 3.10,
192-
# but we backported this for compatibility with older Python versions:
193-
# https://github.com/python/cpython/pull/21921/files#diff-619941af4b328b6abf2dc02c54e774fc17acc1ac4172c14db27d6097cbbff92aR1590
194-
# See also: https://github.com/RagnarGrootKoerkamp/BAPCtools/pull/251#issuecomment-1609353538
195-
# Note: 1031 = fcntl.F_SETPIPE_SZ, but that constant is also only available in Python 3.10.
196-
fcntl.fcntl(pipe, 1031, BUFFER_SIZE)
197-
198189
interaction_file = None
199190
# TODO: Print interaction when needed.
200191
if interaction and interaction is not True:
@@ -231,6 +222,7 @@ def set_pipe_size(pipe):
231222
# TODO: Make a flag to pass validator error directly to terminal.
232223
stderr=subprocess.PIPE if validator_error is False else None,
233224
cwd=validator_dir,
225+
pipesize=BUFFER_SIZE,
234226
preexec_fn=limit_setter(validator_command, validator_timeout, None, 0),
235227
)
236228
validator_pid = validator.pid
@@ -240,17 +232,13 @@ def set_pipe_size(pipe):
240232

241233
assert validator.stdin and validator.stdout
242234

243-
set_pipe_size(validator.stdin)
244-
set_pipe_size(validator.stdout)
245-
if validator_error is False:
246-
set_pipe_size(validator.stderr)
247-
248235
if interaction:
249236
team_tee = subprocess.Popen(
250237
['python3', '-c', TEE_CODE, '>'],
251238
stdin=subprocess.PIPE,
252239
stdout=validator.stdin,
253240
stderr=interaction_file,
241+
pipesize=BUFFER_SIZE,
254242
preexec_fn=limit_setter(None, None, None, gid),
255243
)
256244
team_tee_pid = team_tee.pid
@@ -259,28 +247,24 @@ def set_pipe_size(pipe):
259247
stdin=validator.stdout,
260248
stdout=subprocess.PIPE,
261249
stderr=interaction_file,
250+
pipesize=BUFFER_SIZE,
262251
preexec_fn=limit_setter(None, None, None, gid),
263252
)
264253
val_tee_pid = val_tee.pid
265254

266-
set_pipe_size(team_tee.stdin)
267-
set_pipe_size(val_tee.stdout)
268-
269255
submission = subprocess.Popen(
270256
submission_command,
271257
stdin=(val_tee if interaction else validator).stdout,
272258
stdout=(team_tee if interaction else validator).stdin,
273259
stderr=subprocess.PIPE if team_error is False else None,
274260
cwd=submission_dir,
261+
pipesize=BUFFER_SIZE,
275262
preexec_fn=limit_setter(submission_command, timeout, memory_limit, gid),
276263
)
277264
submission_pid = submission.pid
278265

279266
assert validator.stderr and submission.stderr
280267

281-
if team_error is False:
282-
set_pipe_size(submission.stderr)
283-
284268
stop_kill_handler = threading.Event()
285269
submission_time: Optional[float] = None
286270

0 commit comments

Comments
 (0)