Skip to content

TypeError with joblib while checking "__future__" in code #1905

@FedericoHeichou

Description

@FedericoHeichou

Environment data

  • debugpy version: 1.8.13
  • OS and version: Ubuntu 24.04
  • Python version (& distribution if applicable, e.g. Anaconda): 3.12
  • Using VS Code or Visual Studio: VS Code

Actual behavior

Using joblib (1.5.1) debugpy prints

Traceback (most recent call last):
  File "/root/.vscode-server/extensions/ms-python.debugpy-2025.9.2025052001/bundled/libs/debugpy/_vendored/pydevd/_pydev_bundle/pydev_monkey.py", line 543, in patch_args
    new_args.append(_get_python_c_args(host, port, code, unquoted_args, SetupHolder.setup))
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.vscode-server/extensions/ms-python.debugpy-2025.9.2025052001/bundled/libs/debugpy/_vendored/pydevd/_pydev_bundle/pydev_monkey.py", line 195, in _get_python_c_args
    if "__future__" in code:
       ^^^^^^^^^^^^^^^^^^^^
TypeError: a bytes-like object is required, not 'str'

Expected behavior

Checking if code is byte

Steps to reproduce:

launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Worker",
            "type": "debugpy",
            "request": "launch",
            "module": "app.worker",
            "subProcess": true,  // with this to false we wont debug the subprocess
            "justMyCode": true
        }
    ]
}

app/worker.py

from joblib import Parallel, delayed

def test():
    return 42
Parallel(n_jobs=10)(delayed(test)() for _ in range(10))

Tested monkey patch:

@@ -190,7 +190,8 @@
     setup_repr = setup if setup is None else (sorted_dict_repr(setup))
 
     future_imports = ""
-    if "__future__" in code:
+    future_str = b'__future__' if isinstance(code, bytes) else '__future__'
+    if future_str in code:
         # If the code has a __future__ import, we need to be able to strip the __future__
         # imports from the code and add them to the start of our code snippet.
         future_imports, code = _separate_future_imports(code)

But with this I receive a deadlock

/tmp/venv/lib/python3.12/site-packages/joblib/externals/loky/backend/resource_tracker.py:120: UserWarning: resource_tracker: process died unexpectedly, relaunching.  Some folders/sempahores might leak.
  warnings.warn(

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions