(pyfile, target, run, start_method)
| 44 | ["spawn"] if sys.platform == "win32" else ["spawn", "fork"], |
| 45 | ) |
| 46 | def test_multiprocessing(pyfile, target, run, start_method): |
| 47 | if start_method == "spawn" and sys.platform != "win32": |
| 48 | pytest.skip("https://github.com/microsoft/ptvsd/issues/1887") |
| 49 | |
| 50 | @pyfile |
| 51 | def code_to_debug(): |
| 52 | import debuggee |
| 53 | import multiprocessing |
| 54 | import os |
| 55 | import sys |
| 56 | |
| 57 | # https://github.com/microsoft/ptvsd/issues/2108 |
| 58 | class Foo(object): |
| 59 | pass |
| 60 | |
| 61 | def parent(q, a): |
| 62 | from debuggee import backchannel |
| 63 | |
| 64 | debuggee.setup() |
| 65 | |
| 66 | print("spawning child") |
| 67 | p = multiprocessing.Process(target=child, args=(q, a)) |
| 68 | p.start() |
| 69 | print("child spawned") |
| 70 | |
| 71 | q.put("foo?") |
| 72 | foo = a.get() |
| 73 | assert isinstance(foo, Foo), repr(foo) |
| 74 | |
| 75 | q.put("child_pid?") |
| 76 | what, child_pid = a.get() |
| 77 | assert what == "child_pid" |
| 78 | backchannel.send(child_pid) |
| 79 | |
| 80 | q.put("grandchild_pid?") |
| 81 | what, grandchild_pid = a.get() |
| 82 | assert what == "grandchild_pid" |
| 83 | backchannel.send(grandchild_pid) |
| 84 | |
| 85 | assert backchannel.receive() == "continue" |
| 86 | q.put("exit!") |
| 87 | p.join() |
| 88 | |
| 89 | def child(q, a): |
| 90 | print("entering child") # @bp |
| 91 | assert q.get() == "foo?" |
| 92 | a.put(Foo()) |
| 93 | |
| 94 | assert q.get() == "child_pid?" |
| 95 | a.put(("child_pid", os.getpid())) |
| 96 | |
| 97 | print("spawning child of child") |
| 98 | p = multiprocessing.Process(target=grandchild, args=(q, a)) |
| 99 | p.start() |
| 100 | p.join() |
| 101 | |
| 102 | print("leaving child") |
| 103 |
nothing calls this directly
no test coverage detected
searching dependent graphs…