From 1199e0bdaaa5b7875658790f3cbcd906dc9f7029 Mon Sep 17 00:00:00 2001 From: Andrey Lisin Date: Thu, 11 Jan 2024 19:16:43 +0100 Subject: [PATCH] PY-36882 Fix debugger not working properly with `joblib.Parallel` when using `loky` backend GitOrigin-RevId: 392e04e2e10ae404caf8c561a7c951e7eaea3c9c --- .../pydev/_pydevd_bundle/pydevd_comm.py | 2 ++ python/setup-test-environment/build.gradle | 4 +-- python/testData/debug/test_joblib.py | 8 ++++++ .../PythonDebuggerMultiprocessingTest.java | 28 +++++++++++++++++++ 4 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 python/testData/debug/test_joblib.py diff --git a/python/helpers/pydev/_pydevd_bundle/pydevd_comm.py b/python/helpers/pydev/_pydevd_bundle/pydevd_comm.py index a76b1ed1b458..cd652fbdb5c9 100644 --- a/python/helpers/pydev/_pydevd_bundle/pydevd_comm.py +++ b/python/helpers/pydev/_pydevd_bundle/pydevd_comm.py @@ -291,6 +291,8 @@ class ReaderThread(PyDBDaemonThread): while not self.killReceived: try: r = self.sock.recv(1024) + except OSError: + return except: if not self.killReceived: traceback.print_exc() diff --git a/python/setup-test-environment/build.gradle b/python/setup-test-environment/build.gradle index d167ed023b95..6a954b96de3a 100644 --- a/python/setup-test-environment/build.gradle +++ b/python/setup-test-environment/build.gradle @@ -178,8 +178,8 @@ envs { createPython("python3.11", python311version, - ["black == 23.1.0"], - "python3.11\nblack", + ["black == 23.1.0", "joblib"], + "python3.11\nblack\njoblib", true) createPython("python3.12", diff --git a/python/testData/debug/test_joblib.py b/python/testData/debug/test_joblib.py new file mode 100644 index 000000000000..7b9f64316ac8 --- /dev/null +++ b/python/testData/debug/test_joblib.py @@ -0,0 +1,8 @@ +from joblib import Parallel, delayed + + +def f(i): + print(i) + return i*i + +Parallel(n_jobs=2, backend='loky')(delayed(f)(i) for i in range(3)) diff --git a/python/testSrc/com/jetbrains/env/debug/PythonDebuggerMultiprocessingTest.java b/python/testSrc/com/jetbrains/env/debug/PythonDebuggerMultiprocessingTest.java index a78df528a841..fd2792441080 100644 --- a/python/testSrc/com/jetbrains/env/debug/PythonDebuggerMultiprocessingTest.java +++ b/python/testSrc/com/jetbrains/env/debug/PythonDebuggerMultiprocessingTest.java @@ -340,4 +340,32 @@ public class PythonDebuggerMultiprocessingTest extends PyEnvTestCase { } }); } + + @Test + @TestFor(issues = "PY-36882") + public void testNoErrorMessagesWithJoblib() { + runPythonTest(new PyDebuggerMultiprocessTask("/debug", "test_joblib.py") { + @Override + public void before() { + toggleBreakpoint(4); + } + + @Override + public void testing() throws Exception { + waitForPause(); + resume(); + waitForPause(); + resume(); + waitForPause(); + resume(); + waitForTerminate(); + assertFalse(output().contains("Traceback")); + } + + @Override + public @NotNull Set getTags() { + return Collections.singleton("joblib"); + } + }); + } }