python - 在 Ubuntu 16.04 LTS 中检测与外部云存储同步的目录中的文件更改

标签 python google-cloud-platform google-cloud-storage ubuntu-16.04 python-watchdog

我正在制作一个软件,用于检测新文件是否从虚拟机实例上传到 Google Cloud Platform 的存储桶存储中。通过此命令,使用 Cloud Storage Fuse 将名为 images 的文件目录挂载到存储桶

gcsfuse cloud-storage-bucket ~/mystuff/images

每当文件上传到存储桶时,该文件也会出现在 images 目录中。我正在使用 Python Watchdog 包来检测是否创建了新文件

# -*- coding: utf-8 -*-
#!/bin/bash
import time
import TextDetector
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler

DIR="~/mystuff/images"

class ExampleHandler(FileSystemEventHandler):
    def on_created(self, event): # when file is created
        # do something, eg. call your function to process the image       
        print("Got event for file %s" % event.src_path)
        TextDetector.detect_text(event.src_path)

observer = Observer()
event_handler = ExampleHandler() # create event handler
# set observer to use created handler in directory
observer.schedule(event_handler, path=DIR)
observer.start()

# sleep until keyboard interrupt, then stop + rejoin the observer
try:
    while True:
        time.sleep(1)
except KeyboardInterrupt:
    observer.stop()

observer.join()

问题是看门狗没有检测到任何内容,即使每次我在存储桶存储中上传某些内容时,图像目录中都会创建一个新文件。我也尝试过使用inotify,但结果也是一样。我在Windows平台本地尝试时,代码运行没有任何问题。其实我对 Ubuntu 还很陌生。谁能帮我解决这个问题吗?

最佳答案

您可能需要研究以下选项:

我建议不要在 FUSE 连接器之上构建并利用平台提供的 native 功能。

关于python - 在 Ubuntu 16.04 LTS 中检测与外部云存储同步的目录中的文件更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45874480/

相关文章:

google-app-engine - 错误响应 : [13] An internal error occurred while creating a Google Cloud Storage bucket

python sum(dict.values()) 给出不正确的结果?

google-cloud-storage - 无法使用 gsutil 将文件上传到 GCS

python - 用于 python 的 MS Access 库

node.js - 正确比较 Node 中的数据存储键

caching - Google Cloud Build - 如何缓存 Bazel?

google-maps - Google Maps API 的服务帐户

java - Google云存储Java XML API文件上传并将上传的文件标记为公开

python - Django Rest 框架将字段组合在一起

python - 动态因子模型估计