我使用 subprocess.popen 如下。vscode 中出现以下 linter 建议
try:
p = subprocess.Popen(
["python", "app.py"]
)
except:
traceback.print_exc()
Run Code Online (Sandbox Code Playgroud)
Consider using 'with' for resource-allocating operationspylint(consider-using-with)
Run Code Online (Sandbox Code Playgroud)
但我不知道在哪里使用“with”
用于with分配来自 的变量subprocess.popen()。
try:
with subprocess.Popen(['python', 'app.py']) as p:
# code here
except:
traceback.print_exc()
Run Code Online (Sandbox Code Playgroud)
请注意,try/except还将捕获 主体中的异常with。请参阅此答案,了解如何构建代码以捕获异常subprocess.Popen()。
| 归档时间: |
|
| 查看次数: |
4647 次 |
| 最近记录: |