admin管理员组文章数量:1399805
I'm trying to schedule an automated task that runs a python script "myscript1.py" in VS Code.
First step is to run the command "poetry shell" which spawns a new shell:
PS C:\dir1\dir2> poetry shell
Spawning shell within C:\dir1\dir2\.venv
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
Install the latest PowerShell for new features and improvements!
(dir1-py3.12) PS C:\dir1>
I put this as the command of the first task. Then I put the actual script as the command of the second task. This creates two tasks, one that opens a Poetry shell and the other that opens a different terminal window.
My purpose is to spawn the Poetry shell within which to run the "myscript1.py."
Here are the two files:
tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"label": "spawn_poetry_shell",
"type": "shell",
"command": "poetry shell",
"group": "group1",
"presentation": {
"reveal": "always",
"panel": "new"
},
{
"label": "run_script",
"type": "shell",
"command": "python C:\\dir1\\dir2\\myscript1.py",
"group": "group1",
"presentation": {
"reveal": "always",
"panel": "new"
},
"problemMatcher": "$msCompile"
}
]
}
settings.json:
{
"workbench.colorTheme": "Default High Contrast",
"terminal.integrated.scrollback": 4000,
"task.allowAutomaticTasks": "on",
"tasks": [
{
"at": "16 16 * * *",
"run": "workbench.action.tasks.runTask",
"args": ["spawn_poetry_shell"]
},
{
"at": "17 16 * * *",
"run": "workbench.action.tasks.runTask",
"args": ["run_script"]
},
],
"workbench.startupEditor": "none",
}
The poetry.lock, .venv, .vscode files and the "dir2" directory are located under C:\dir1
, whereas the "myscript1.py" script is located under the C:\dir1\dir2\
directory.
I'm trying to schedule an automated task that runs a python script "myscript1.py" in VS Code.
First step is to run the command "poetry shell" which spawns a new shell:
PS C:\dir1\dir2> poetry shell
Spawning shell within C:\dir1\dir2\.venv
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
Install the latest PowerShell for new features and improvements! https://aka.ms/PSWindows
(dir1-py3.12) PS C:\dir1>
I put this as the command of the first task. Then I put the actual script as the command of the second task. This creates two tasks, one that opens a Poetry shell and the other that opens a different terminal window.
My purpose is to spawn the Poetry shell within which to run the "myscript1.py."
Here are the two files:
tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"label": "spawn_poetry_shell",
"type": "shell",
"command": "poetry shell",
"group": "group1",
"presentation": {
"reveal": "always",
"panel": "new"
},
{
"label": "run_script",
"type": "shell",
"command": "python C:\\dir1\\dir2\\myscript1.py",
"group": "group1",
"presentation": {
"reveal": "always",
"panel": "new"
},
"problemMatcher": "$msCompile"
}
]
}
settings.json:
{
"workbench.colorTheme": "Default High Contrast",
"terminal.integrated.scrollback": 4000,
"task.allowAutomaticTasks": "on",
"tasks": [
{
"at": "16 16 * * *",
"run": "workbench.action.tasks.runTask",
"args": ["spawn_poetry_shell"]
},
{
"at": "17 16 * * *",
"run": "workbench.action.tasks.runTask",
"args": ["run_script"]
},
],
"workbench.startupEditor": "none",
}
The poetry.lock, .venv, .vscode files and the "dir2" directory are located under C:\dir1
, whereas the "myscript1.py" script is located under the C:\dir1\dir2\
directory.
1 Answer
Reset to default 0The poetry shell starts a new subshell and blocks subsequent commands.
Run commands directly using poetry:
"command": "poetry.exe",
"args": [
"run",
"python",
"myscript1.py"
],
本文标签: pythonHow to run a task in the poetry shellStack Overflow
版权声明:本文标题:python - How to run a task in the poetry shell - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744226700a2596126.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论