简体   繁体   English

如何远程调用 a.py 脚本?

[英]How can I invoke a .py script remotely?

I have a script on my local machine that I would like to run remotely.我的本地机器上有一个脚本,我想远程运行。 This script requires a lot of GPU power so I can't run it from my laptop or phone which I would like to do.该脚本需要大量 GPU 电源,因此我无法从我想做的笔记本电脑或手机上运行它。 If there's any way I could connect to my local machines powershell or command prompt please let me know.如果有任何方法可以连接到我的本地机器 powershell 或命令提示符,请告诉我。

Use ssh, exemple:使用 ssh,例如:

ssh user@192.254.2.145 python - ssh 用户@192.254.2.145 python -

There are many services that offer free use of GPUs (and the ability to upgrade to paid services).有许多服务提供免费使用 GPU(以及升级到付费服务的能力)。

Some of the big providers are:一些大型供应商是:

But there are many more !但还有更多

This image gives a good overview of the services above:此图像很好地概述了上述服务:

在此处输入图像描述

Feel free to read more here .随意在这里阅读更多

I don't know about running PowerShell commands on mobile...我不知道在移动设备上运行 PowerShell 命令...

However, as long as you have your computer set up for remote access (WARNING: dangerous if you are exposing it over the internet and not simply local) (see PowerShell Remote and WSMan), then the following would be simple:但是,只要您将计算机设置为远程访问(警告:如果您将其暴露在 Internet 上而不是简单地在本地公开它是危险的)(请参阅PowerShell 远程和 WSMan),那么以下内容将很简单:

$cred = Get-Credential -Message "local machine credentials"
Invoke-Command -Credential $cred -ComputerName <your local IP> -ScriptBlock {
    C:\path\to\python.exe C:\path\to\script.py
}

Something that would be safer would be to expose it through a REST API.更安全的方法是通过 REST API 公开它。 This approach would be safer from a security standpoint (although there may still be either attacks or other people utilizing your local machine if exposed publicly).从安全的角度来看,这种方法会更安全(尽管如果公开暴露,可能仍然存在攻击或其他人使用您的本地计算机)。 You could then either design it so that any browser can render your output with HTML (see Flask if you want to use Python on your local machine), or you could return json and have a script on your mobile that parses and renders it or whatever you wish. You could then either design it so that any browser can render your output with HTML (see Flask if you want to use Python on your local machine), or you could return json and have a script on your mobile that parses and renders it or whatever你希望。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM