[英]Running python script infinitely on a server
I am building a python script which needs to run infinitely on a server.我正在构建一个需要在服务器上无限运行的 python 脚本。 It will access a Microsoft Exchange server and read mails, process them and trigger automated voice calls.
它将访问 Microsoft Exchange 服务器并阅读邮件、处理邮件并触发自动语音呼叫。
I have successfully implemented the automated call action.我已经成功实现了自动呼叫操作。 Presently the script runs on my PC.
目前该脚本在我的 PC 上运行。 I have three questions.
我有三个问题。
If your goal is to run the python server as a service on the server, then more information about what type of server (windows/linux) is required.如果您的目标是将 python 服务器作为服务器上的服务运行,则需要有关服务器类型(windows/linux)的更多信息。 Assuming you are considering running it on an exchange server, I suppose it's most likely you'll want to run on Windows.
假设您正在考虑在交换服务器上运行它,我想您很可能希望在 Windows 上运行。 This has been asked and answered here .
这已被问及回答here 。 In relation to your code, you will want to make sure your script can be handled as a library, and you won't want to call
sys.exit
inside your code, but should rely on exceptions to pass up errors.关于您的代码,您需要确保您的脚本可以作为库处理,并且您不想在代码中调用
sys.exit
,而是应该依靠异常来传递错误。 My preferred pattern is something like我喜欢的模式是
def main(argv=None):
# parse arguments if you have them and run the script
if __name__ == '__main__':
main()
Then in your service you can import and call main(...)
without running another executable.然后在您的服务中,您可以导入并调用
main(...)
而不运行另一个可执行文件。
See #1.见#1。 Whether it can run on that server depends on whether all of the required resources and files are available there.
它是否可以在该服务器上运行取决于那里是否有所有必需的资源和文件。 There is possibly a question of whether you would WANT to run the script on your exchange server.
可能存在您是否想在您的交换服务器上运行脚本的问题。 That answer depends on the load the script takes, how busy/active your server is, Whether you want the extra software installed on your server, etc.
该答案取决于脚本的负载、服务器的繁忙/活跃程度、是否要在服务器上安装额外的软件等。
Your best solution here will depend on your situation.您在这里的最佳解决方案将取决于您的情况。 If you can login and edit the files, then maybe that's what you do.
如果您可以登录并编辑文件,那么也许您就是这样做的。 If you want to edit them on your PC and then push them up, then there are solutions for that.
如果您想在 PC 上编辑它们然后将它们向上推送,那么有解决方案。 All depends on what makes sense for your project/situation.
一切都取决于对您的项目/情况有意义的事情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.