-
Notifications
You must be signed in to change notification settings - Fork 67
Simple ProcessPoolExecutor example code fails in VSCode-Python #1228
Description
@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:
- Setup a basic Python 3.6 environment in VSCode.
- Create an
__init__.py
file and add the above script to it. - 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.)