Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita1f4a6b

Browse files
gh-132912: Use readline to synchronize between procs in remote pdb test (#132949)
1 parent947c4f1 commita1f4a6b

File tree

1 file changed

+11
-20
lines changed

1 file changed

+11
-20
lines changed

‎Lib/test/test_remote_pdb.py‎

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -469,12 +469,6 @@ def test_breakpoints(self):
469469

470470
deftest_keyboard_interrupt(self):
471471
"""Test that sending keyboard interrupt breaks into pdb."""
472-
synchronizer_sock=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
473-
synchronizer_sock.bind(('127.0.0.1',0))# Let OS assign port
474-
synchronizer_sock.settimeout(SHORT_TIMEOUT)
475-
synchronizer_sock.listen(1)
476-
self.addCleanup(synchronizer_sock.close)
477-
sync_port=synchronizer_sock.getsockname()[1]
478472

479473
script=textwrap.dedent(f"""
480474
import time
@@ -491,11 +485,10 @@ def bar():
491485
version=pdb._PdbServer.protocol_version(),
492486
)
493487
print("Connected to debugger")
494-
iterations = 10
495-
socket.create_connection(('127.0.0.1',{sync_port})).close()
488+
iterations = 50
496489
while iterations > 0:
497-
print("Iteration", iterations)
498-
time.sleep(1)
490+
print("Iteration", iterations, flush=True)
491+
time.sleep(0.2)
499492
iterations -= 1
500493
return 42
501494
@@ -512,22 +505,20 @@ def bar():
512505
# Continue execution
513506
self._send_command(client_file,"c")
514507

515-
# Wait until execution has continued
516-
synchronizer_sock.accept()[0].close()
517-
518-
# Wait a bit so the remote leaves create_connection(). This is not
519-
# required but makes the rest of the test faster as we will exit the main
520-
# loop immediately by setting iterations to 0.
521-
time.sleep(0.1)
508+
# Confirm that the remote is already in the while loop. We know
509+
# it's in bar() and we can exit the loop immediately by setting
510+
# iterations to 0.
511+
whileline:=process.stdout.readline():
512+
ifline.startswith("Iteration"):
513+
break
522514

523515
# Inject a script to interrupt the running process
524516
self._send_interrupt(process.pid)
525517
messages=self._read_until_prompt(client_file)
526518

527-
# Verify we got the keyboard interrupt message. Is possible that we get interrupted somewhere
528-
# in bar() or when leving create_connection()
519+
# Verify we got the keyboard interrupt message.
529520
interrupt_msgs= [msg['message']formsginmessagesif'message'inmsg]
530-
expected_msg= [msgformsgininterrupt_msgsif"bar()"inmsgor"create_connection()"inmsg]
521+
expected_msg= [msgformsgininterrupt_msgsif"bar()"inmsg]
531522
self.assertGreater(len(expected_msg),0)
532523

533524
# Continue to end as fast as we can

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp