(pyfile, target, run)
| 504 | sys.platform != "win32", reason="job objects are specific to Windows" |
| 505 | ) |
| 506 | def test_breakaway_job(pyfile, target, run): |
| 507 | @pyfile |
| 508 | def child(): |
| 509 | import os |
| 510 | from debuggee import backchannel |
| 511 | |
| 512 | backchannel.send(os.getpid()) |
| 513 | backchannel.receive() |
| 514 | backchannel.send("ok") |
| 515 | |
| 516 | @pyfile |
| 517 | def parent(): |
| 518 | import debuggee |
| 519 | import os |
| 520 | import subprocess |
| 521 | import sys |
| 522 | |
| 523 | debuggee.setup() |
| 524 | argv = [sys.executable, sys.argv[1]] |
| 525 | env = os.environ.copy() |
| 526 | pipe_in = open(os.devnull, "r") |
| 527 | pipe_out = open(os.devnull, "w") |
| 528 | CREATE_BREAKAWAY_FROM_JOB = 0x01000000 |
| 529 | proc = subprocess.Popen( |
| 530 | argv, |
| 531 | env=env, |
| 532 | stdin=pipe_in, |
| 533 | stdout=pipe_out, |
| 534 | stderr=pipe_out, |
| 535 | creationflags=CREATE_BREAKAWAY_FROM_JOB, |
| 536 | ) |
| 537 | pipe_in.close() |
| 538 | pipe_out.close() |
| 539 | proc.wait() |
| 540 | |
| 541 | with debug.Session() as parent_session: |
| 542 | parent_session.config.update( |
| 543 | { |
| 544 | "redirectOutput": False, |
| 545 | "subProcess": False, |
| 546 | } |
| 547 | ) |
| 548 | parent_session.expected_exit_code = some.int |
| 549 | backchannel = parent_session.open_backchannel() |
| 550 | |
| 551 | with run(parent_session, target(parent, args=[child])): |
| 552 | pass |
| 553 | |
| 554 | child_pid = backchannel.receive() |
| 555 | child_process = psutil.Process(child_pid) |
| 556 | |
| 557 | parent_session.request("terminate") |
| 558 | parent_session.wait_for_exit() |
| 559 | |
| 560 | # child should still be running |
| 561 | backchannel.send("proceed") |
| 562 | assert backchannel.receive() == "ok" |
| 563 |
nothing calls this directly
no test coverage detected
searching dependent graphs…