简体   繁体   English

如何让 Google 云虚拟机实例运行数小时?

[英]How do I keep Google cloud VM instance running for hours?

So, I have written a python script on Windows that uploads 1000s of images to a website with additional data and steps.因此,我在 Windows 上编写了一个 python 脚本,该脚本将 1000 张图像上传到带有附加数据和步骤的网站。 It uses pyautogui, pickle, random and os libraries.它使用 pyautogui、pickle、random 和 os 库。 And I want to run it on google cloud and don't want my device to be turned on that long.我想在谷歌云上运行它,不希望我的设备打开那么久。 Script should run approximately for 30 hours non-stop.脚本应不间断运行大约 30 小时。 And I need to have gui, keyboard and everything up 'cause the script locates screenshots of buttons and fields then clicks or writes.我需要有 gui、键盘和一切,因为脚本会找到按钮和字段的屏幕截图,然后点击或写入。 Basically I want that script to run for ~30 hours under the same conditions as when I'm on, but without me logged in. How do I do that?基本上,我希望该脚本在与我开机时相同的条件下运行约 30 小时,但没有我登录。我该怎么做?

You could use pythonw.exe to run your script.您可以使用pythonw.exe来运行您的脚本。 Here you can find a very good explanation on how it works and when to use it 1 .在这里您可以找到关于它如何工作以及何时使用它的很好的解释1

"As per Python documentation: “根据 Python 文档:

  1. python.exe is associated with.py files and runs in python terminal. python.exe 与.py 文件关联,并在 python 终端中运行。

  2. pythonw.exe is associated with.pyw files and does not run in the terminal. pythonw.exe 与.pyw 文件相关联,不在终端中运行。 It is for a GUI program.它适用于 GUI 程序。

  3. When python.exe runs the program, a black console window (also called the command line window, DOS / CMD window) will pop up.当python.exe运行程序时,会弹出一个黑色控制台window(也叫命令行window,DOS/ZA28966BAC17B8EEF90ZEB3A窗口)。

  4. pythonw.exe is a windowless Python executable program, which means that when running the program, there is no window and the code is executed in the background. pythonw.exe是一个无窗口的Python可执行程序,也就是说运行程序时没有window,代码在后台执行。

The difference between.py and.pyw files also comes from the difference between python.exe and pythonw.exe. .py 和 .pyw 文件的区别也来自于 python.exe 和 pythonw.exe 的区别。 When installing Python for Windows, Files with a.py extension are defaulted to run with python.exe, and.pyw files are defaulted to run with pythonw.exe.为Windows安装Python时,扩展名为.py的文件默认使用python.exe运行,.pyw文件默认使用pythonw.exe运行。

The.pyw format is designed to run pure graphical interface programs that are developed. .pyw 格式旨在运行开发的纯图形界面程序。 Users of pure graphical interface programs do not need to see the console window.纯图形界面程序的用户不需要看控制台window。 When developing a program with a pure graphical interface, you can temporarily change.pyw to.py, and the console window can be called up at runtime to easily see all error messages."开发纯图形界面的程序时,可以临时将.pyw改成.py,运行时可以调出控制台window,方便查看所有错误信息。”

You can take a look at the official documentation for more information here: 2 .您可以在此处查看官方文档以获取更多信息: 2

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

相关问题 谷歌云虚拟机保持 jupyter 运行 - Google Cloud VM keep jupyter running 如何使Python应用程序在EC2实例中运行? - How do I keep a Python application running in an EC2 instance? Selenium Google Cloud VM 实例的替代方案? - Selenium Alternatives for Google Cloud VM instance? Google Cloud Function / MongoDB VM 实例通信 - Google Cloud Function / MongoDB VM instance communication 在 google VM 上运行 python 脚本 - Keep a python script running on google VM 如何使用 Google Cloud Function 将 ip 添加到 Cloud SQL 实例的授权网络? - How do I use a Google Cloud Function to add an ip to the authorized networks of a Cloud SQL instance? 如何从浏览器访问在 Google Compute Engine VM 上运行的 Django? - How do I access Django running on a Google Compute Engine VM from my browser? 如何将 tensorflow 事件从 VM 实例内的 Docker 容器写入谷歌云存储 - How to write tensorflow events to google cloud storage from Docker container inside VM instance 如何将旧的 Django Google App Engine 应用程序升级到第二代云 SQL 实例? - How do I upgrade an old Django Google App Engine application to a Second Generation Cloud SQL Instance? Google Compute Engine VM实例的“ Cloud Datastore”权限 - “Cloud Datastore” permission for Google Compute Engine VM instance
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM