python - 为什么 awscli sync 在我的 Windows 服务中不起作用?
问题描述
我想编写一些代码,每 10 秒将本地目录同步到 s3 存储桶作为 Windows 服务。为此,我正在使用 aws cli sync,并正在使用os.system
访问 aws CLI。
这是我的代码的一个简单示例:
x = 'aws s3 sync C:\path\to\folder s3://bucket-to-sync/'
def syncDirectory(*args)
os.system(*args)
syncDirectory(x)
现在,此代码在常规 python 脚本中工作正常并按预期同步。但是,当我创建它并将其作为 Windows 服务运行时,它不会同步。
我已使用此页面中的代码来创建和运行服务,并且只是将 main 函数替换为上面列出的代码。
class PythonCornerExample(SMWinservice):
_svc_name_ = "ServiceTest"
_svc_display_name_ = "Service Example"
_svc_description_ = "Syncing dir to s3 bucket"
def start(self):
self.isrunning = True
def stop(self):
self.isrunning = False
def main(self):
while self.isrunning:
os.system('aws s3 sync C:\path\to\folder s3://bucket-to-sync/')
time.sleep(10)
if __name__ == '__main__':
PythonCornerExample.parse_command_line()
我不确定为什么这不起作用,我尝试从命令提示符调试此代码,但它说它工作正常,但我的存储桶中没有显示任何内容。任何帮助表示赞赏。
解决方案
推荐阅读
- ios - UIImageView 显示图像时如何防止 UIToolbar 调整大小?
- python - 如何对字符串中的日期进行排序?(Python)
- ios - 如何在 ARSCNFaceGeometry 网格周围绘制自定义边界
- docker - 如何使用本地 nuget 包源进行 Dockerfile dotnet restore
- php - 导入的 csv 文件无法在 laravel 中显示
- android - 如何连接或使用 NDK 和 Nativescript vuejs
- embedded-linux - Hi3516D:使用 uboot 从 NFS 引导时出现内核恐慌
- mysql - 如何打开 .exp 文件?
- android - AAR 文件中的类在 Android Studio 中不可用
- vb.net - 如果空行,Streamreader 读取下一行