Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't import asyncio early to avoid importing multiprocessing. #78

Merged
merged 1 commit into from
Mar 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from pydevd_concurrency_analyser.pydevd_thread_wrappers import ObjectWrapper, wrap_attr
import pydevd_file_utils
from _pydev_bundle import pydev_log
import sys

file_system_encoding = getfilesystemencoding()

Expand All @@ -29,11 +30,6 @@
# return time since epoch in milliseconds
cur_time = lambda: int(round(time.time() * 1000000))

try:
import asyncio # @UnresolvedImport
except:
pass


def get_text_list_for_frame(frame):
# partial copy-paste from make_thread_suspend_str
Expand Down Expand Up @@ -255,6 +251,12 @@ def __init__(self):
self.start_time = cur_time()

def get_task_id(self, frame):
asyncio = sys.modules.get('asyncio')
if asyncio is None:
# If asyncio was not imported, there's nothing to be done
# (also fixes issue where multiprocessing is imported due
# to asyncio).
return None
while frame is not None:
if "self" in frame.f_locals:
self_obj = frame.f_locals["self"]
Expand All @@ -275,6 +277,14 @@ def log_event(self, frame):

if not hasattr(frame, "f_back") or frame.f_back is None:
return

asyncio = sys.modules.get('asyncio')
if asyncio is None:
# If asyncio was not imported, there's nothing to be done
# (also fixes issue where multiprocessing is imported due
# to asyncio).
return

back = frame.f_back

if "self" in frame.f_locals:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from multiprocessing import Process, Queue


class Foo:

def __init__(self, value):
self.value = value # break 2 here


def f(q):
q.put(Foo(1))


if __name__ == '__main__':
q = Queue()
p = Process(target=f, args=(q,))
p.start()
print(q.get().value) # break 1 here
print('TEST SUCEEDED!')
p.join()
1 change: 1 addition & 0 deletions src/debugpy/_vendored/pydevd/tests_python/test_debugger.py
Original file line number Diff line number Diff line change
Expand Up @@ -2368,6 +2368,7 @@ def get_environ(writer):

@pytest.mark.skipif(not IS_CPYTHON, reason='CPython only test.')
@pytest.mark.parametrize('file_to_check', [
'_debugger_case_multiprocessing_2.py',
'_debugger_case_multiprocessing.py',
'_debugger_case_python_c.py',
'_debugger_case_multiprocessing_pool.py'
Expand Down