I wrote a following simple python code that does listen to changes to files in a folder, and uploads them to 3 different S3 buckets and works well. I would like to do uploading to all 3 buckets parallely.
Approx 4 files of 500KB generated/updated every seconds, so 4 files being uploaded to 3 buckets per second.
Two options are ThreadPoolExecutor and asyncio. What is right approach for this and what are other options ?
Please ignore that I am using pyinotify for watching changes and its old lib.
from http import client
import pyinotify
from boto_client import S3Client
class MyEventHandler(pyinotify.ProcessEvent):
def __init__(self):
self.s3Client = S3Client()
def process_IN_CLOSE_WRITE(self, event):
self.s3Client.upload_file("bucket_1",event.pathname)
self.s3Client.upload_file("bucket_2",event.pathname)
self.s3Client.upload_file("bucket_3",event.pathname)
def main():
wm = pyinotify.WatchManager()
wm.add_watch('./tmp', pyinotify.IN_MOVED_TO | pyinotify.IN_CLOSE_WRITE, rec=True)
eh = MyEventHandler()
notifier = pyinotify.Notifier(wm, eh)
notifier.loop()
if __name__ == '__main__':
main()
source https://stackoverflow.com/questions/76239512/uploading-files-to-multiple-s3-buckets-when-local-file-changes
Comments
Post a Comment