Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Debug multiprocess leads to AttributeError Can't get attribute on <module '__main__

Don't import multiprocessing before running user code.

Use bytes rather than unicode for __main__.__name__ on Python 2.7.
  • Loading branch information
int19h committed Mar 18, 2020
1 parent c12cb6b commit 341a706
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"version": "0.2.0",
"configurations": [
{
"debugAdapterPath": "${workspaceFolder}/src/debugpy/adapter",
"name": "Launch Python file",
"type": "python",
"request": "launch",
Expand All @@ -14,6 +15,7 @@
"logToFile": true,
},
{
"debugAdapterPath": "${workspaceFolder}/src/debugpy/adapter",
"name": "Attach: connect",
"type": "python",
"request": "attach",
Expand All @@ -24,6 +26,7 @@
}
},
{
"debugAdapterPath": "${workspaceFolder}/src/debugpy/adapter",
"name": "Attach: listen",
"type": "python",
"request": "attach",
Expand All @@ -34,12 +37,14 @@
}
},
{
"debugAdapterPath": "${workspaceFolder}/src/debugpy/adapter",
"name": "Attach: PID",
"type": "python",
"request": "attach",
"processId": "${command:pickProcess}"
},
{
"debugAdapterPath": "${workspaceFolder}/src/debugpy/adapter",
"name": "Debug Tests",
"type": "python",
"request": "test",
Expand Down
2 changes: 0 additions & 2 deletions src/debugpy/common/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,6 @@ def prefixed(format_string, *args, **kwargs):


def describe_environment(header):
import multiprocessing
import sysconfig
import site # noqa

Expand Down Expand Up @@ -321,7 +320,6 @@ def report_paths(get_paths, label=None):

prefix = " " * len(prefix)

report("CPU count: {0}\n\n", multiprocessing.cpu_count())
report("System paths:\n")
report_paths("sys.prefix")
report_paths("sys.base_prefix")
Expand Down
2 changes: 1 addition & 1 deletion src/debugpy/server/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def run_file():
log.describe_environment("Pre-launch environment:")
log.info("Running file {0!r}", options.target)

runpy.run_path(options.target, run_name="__main__")
runpy.run_path(options.target, run_name=compat.force_str("__main__"))


def run_module():
Expand Down
11 changes: 11 additions & 0 deletions tests/debugpy/test_multiproc.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ def code_to_debug():
import os
import sys

# https://github.com/microsoft/ptvsd/issues/2108
class Foo(object):
pass

def parent(q, a):
from debuggee import backchannel

Expand All @@ -49,6 +53,10 @@ def parent(q, a):
p.start()
print("child spawned")

q.put("foo?")
foo = a.get()
assert isinstance(foo, Foo), repr(foo)

q.put("child_pid?")
what, child_pid = a.get()
assert what == "child_pid"
Expand All @@ -65,6 +73,9 @@ def parent(q, a):

def child(q, a):
print("entering child")
assert q.get() == "foo?"
a.put(Foo())

assert q.get() == "child_pid?"
a.put(("child_pid", os.getpid()))

Expand Down

0 comments on commit 341a706

Please sign in to comment.