MCPcopy Index your code
hub / github.com/RustPython/RustPython / _run_child

Method _run_child

Lib/test/test_builtin.py:2582–2642  ·  view source on GitHub ↗
(self, child, terminal_input)

Source from the content-addressed store, hash-verified

2580 signal.signal(signal.SIGHUP, old_sighup)
2581
2582 def _run_child(self, child, terminal_input):
2583 r, w = os.pipe() # Pipe test results from child back to parent
2584 try:
2585 pid, fd = pty.fork()
2586 except (OSError, AttributeError) as e:
2587 os.close(r)
2588 os.close(w)
2589 self.skipTest("pty.fork() raised {}".format(e))
2590 raise
2591
2592 if pid == 0:
2593 # Child
2594 try:
2595 os.close(r)
2596 with open(w, "w") as wpipe:
2597 child(wpipe)
2598 except:
2599 traceback.print_exc()
2600 finally:
2601 # We don't want to return to unittest...
2602 os._exit(0)
2603
2604 # Parent
2605 os.close(w)
2606 os.write(fd, terminal_input)
2607
2608 # Get results from the pipe
2609 with open(r, encoding="utf-8") as rpipe:
2610 lines = []
2611 while True:
2612 line = rpipe.readline().strip()
2613 if line == "":
2614 # The other end was closed => the child exited
2615 break
2616 lines.append(line)
2617
2618 # Check the result was got and corresponds to the user's terminal input
2619 if len(lines) != 2:
2620 # Something went wrong, try to get at stderr
2621 # Beware of Linux raising EIO when the slave is closed
2622 child_output = bytearray()
2623 while True:
2624 try:
2625 chunk = os.read(fd, 3000)
2626 except OSError: # Assume EIO
2627 break
2628 if not chunk:
2629 break
2630 child_output.extend(chunk)
2631 os.close(fd)
2632 child_output = child_output.decode("ascii", "ignore")
2633 self.fail("got %d lines in pipe but expected 2, child output was:\n%s"
2634 % (len(lines), child_output))
2635
2636 # bpo-40155: Close the PTY before waiting for the child process
2637 # completion, otherwise the child process hangs on AIX.
2638 os.close(fd)
2639

Callers 1

run_childMethod · 0.95

Calls 15

lenFunction · 0.85
skipTestMethod · 0.80
print_excMethod · 0.80
openFunction · 0.50
pipeMethod · 0.45
closeMethod · 0.45
formatMethod · 0.45
_exitMethod · 0.45
writeMethod · 0.45
stripMethod · 0.45
readlineMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected