Skip to content
This repository was archived by the owner on Aug 2, 2023. It is now read-only.
This repository was archived by the owner on Aug 2, 2023. It is now read-only.

Simple ProcessPoolExecutor example code fails in VSCode-Python #1228

@DonJayamanne

Description

@DonJayamanne

@ericdrobinson commented on Fri Mar 08 2019

The following simple script was adapted from the "Executing code in thread or process pools" documentation for Python 3.7. The adaptations allow the code to be run in Python 3.6.

import asyncio
import concurrent.futures
import os

def cpu_bound():
    print(os.getpid())
    return sum(i * i for i in range(10 ** 7))

async def main():
    print(os.getpid())
    loop = asyncio.get_event_loop()

    # Run in a custom process pool:
    with concurrent.futures.ProcessPoolExecutor() as pool:
        result = await loop.run_in_executor(
            pool, cpu_bound)
        print('custom process pool', result)

if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    loop.run_until_complete(main())
    loop.close()
    print('done')

Running the code above with the Python: Current File (Integrated Terminal) debugger profile appears to result in a deadlock (no pid is printed from the cpu_bound function). Running that very same code directly with Python 3.6 via the command line works as expected. If the ProcessPoolExecutor is replaced with ThreadPoolExecutor the code appears to run fine using the debugger.

Environment data

  • VS Code version: 1.32.1
  • Extension version: 2019.2.5558
  • OS and version: macOS 10.14.3
  • Python version (& distribution if applicable, e.g. Anaconda): Anaconda 3.6.7
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): conda
  • Relevant/affected Python packages and their versions: NA

Expected behaviour

The script runs to completion and prints two pid numbers and the result of the computation:

10385
10386
custom process pool 333333283333335000000
done

Actual behaviour

The script prints the first pid and then pauses until the user manually stops the debugger. Output:

10412

Steps to reproduce:

  1. Setup a basic Python 3.6 environment in VSCode.
  2. Create an __init__.py file and add the above script to it.
  3. Use the vscode-python extension to attempt to debug the __init__.py file with the "Python: Current File (Integrated Terminal)" launch profile.

Logs

Output for Python in the Output panel: None.

Output from Console under the Developer Tools panel: None. (Not strictly true. There is an "[Extension Host] undefined session received in acceptDebugSessionStarted" error but it seems unrelated as it appears regardless of the contents of the file being debugged.)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions