-
Notifications
You must be signed in to change notification settings - Fork 69
Simple ProcessPoolExecutor example code fails in VSCode-Python #1228
Comments
Note due to #943, you have to set import multiprocessing
multiprocessing.set_start_method('spawn', True)
import os
import concurrent.futures
import asyncio
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') Launch json: {
"name": "Terminal",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "."
}
],
"subProcess": true,
}, This is what i see in the terminal: 6281
6297
custom process pool 333333283333335000000
done |
@ericdrobinson Let me know if the above change to code works for you. |
@karthiknadig That did indeed work for the specific example I outlined in the initial ticket. Unfortunately, the code I posted in the initial ticket is a very minimal repro-case. The actual environment I'm working with is a bit more complicated. Specifically, I first ran into this issue while working with However, when I tried your fix in the actual project it broke things. Specifically, I encountered the following exception:
As I understand it, the |
Hi @ericdrobinson! Is there anyway you can provide us with more information? For example, your launch.json and settings.json files as well as some of the code you are working with? It's difficult for us to repro this issue without that information. As well, have you tried using the Azure Functions extension for VS Code? It allows you to debug Azure Functions directly from VS Code. Currently, Python support is in preview mode, but it might help if you take a look at the link here. |
@Anapo14 Please find my responses broken out below:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Terminal (integrated)",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
},
{
"name": "Attach to Python Functions",
"type": "python",
"request": "attach",
"port": 9091,
"host": "localhost",
"preLaunchTask": "runFunctionsHost"
}
]
}
{
"azureFunctions.projectRuntime": "~2",
"azureFunctions.projectLanguage": "Python",
"azureFunctions.templateFilter": "Verified",
"azureFunctions.deploySubpath": "[REDACTED].zip",
"azureFunctions.preDeployTask": "funcPack",
"files.exclude": {
"obj": true,
"bin": true
},
"azureFunctions.pythonVenv": ".env",
"debug.internalConsoleOptions": "neverOpen",
"editor.rulers": [79],
"python.pythonPath": ".env/bin/python"
}
No, because that's proprietary and not something I'm at liberty to post in an open forum such as this. That said, I will point out that running the exact code I initially posted in a simple HTTP Trigger will produce exactly the updated experience I described. To that end, please see the following: Environment Data
Steps to Reproduce
BehaviourAs configured above, the debugger pauses on the following exception:
At this point, the Terminal output (for the terminal named "Task - runFunctionsHost") is as follows:
If you comment out the
I should mention that I also "chronicled" my attempts to figure out how to use the
Yes. This is where I first ran into the issue described in the initial report. Please see the above sections of this comment for a deeper dive and a working example that shows how the workflow you suggest here breaks with the suggested workaround. |
It seems that the issue is that multiprocessing is using Unfortunately it seems that in the example given |
@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.
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 theProcessPoolExecutor
is replaced withThreadPoolExecutor
the code appears to run fine using the debugger.Environment data
Expected behaviour
The script runs to completion and prints two pid numbers and the result of the computation:
Actual behaviour
The script prints the first pid and then pauses until the user manually stops the debugger. Output:
Steps to reproduce:
__init__.py
file and add the above script to it.__init__.py
file with the "Python: Current File (Integrated Terminal)" launch profile.Logs
Output for
Python
in theOutput
panel: None.Output from
Console
under theDeveloper 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.)The text was updated successfully, but these errors were encountered: