Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6337963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:21:06+00:00 2026-05-24T19:21:06+00:00

I have a multithreaded python application that does a bunch of processing on files.

  • 0

I have a multithreaded python application that does a bunch of processing on files.

The main application is scanning a directory for new files. Whenever a file is found, this file is being processed (Image/Video editing, FTP uploading, saving metadata to a DB…) in other Python threads. A large part of those Processors are running external commands with Popen and waiting for them to return.

When I process a single file, I don’t have any problem and everything works fine, but when the main application is running, it leads to a random behavior and I end up having a bunch of errors like Popen command not returning, FTP server dropping the connection, etc…

Here is a simplified version of my application, for illustration purposes:

class VideoEditor(Thread):
    def __init__(self, file, manager):
        Thread.__init__(self);
        self.manager = manager
        self.file = file


    def run(self):
        Popen('some video editing command').wait()

        self.manager.on_video_editing_finished(self)

class FileUploader(Thread):
    def __init__(self, file, manager):
        Thread.__init__(self);
        self.manager = manager
        self.file = file

    def run(self):
        # Uploading the file to ftp server

        self.manager.on_upload_finished(self)

class Manager():
    def __init__(self):
        self.video_editors = []
        self.uploaders = []

    def on_upload_finished(self, uploader):
        self.uploaders.remove(uploader)
        file = uploader.file
        print "Processing finished for %s" % file


    def on_video_editing_finished(self, video_editor):
        self.video_editors.remove(video_editor)
        file = video_editor.file
        u = FileUploader(file, self)
        u.start()
        self.uploaders.append(u)

    def scan_and_process(self):
        # Detect new file
        ve = VideoEditor(new_file, self)
        ve.start()
        self.video_editors.append(ve)

if __name__ == "__main__":
    manager = Manager()
    while True:
        manager.scan_and_process()
        sleep(60)

Is there a better design for doing this? Am I doing something wrong here?

EDIT: Idea
Would this way be better?

def process_file(file):
    Popen('some video editing command').wait()
    Popen('some other command').wait()
    # Upload to FTP here

class Manager():
    def scan_and_process(self):
        # Detect new file
        Popen(['python', 'Manager.py', '-process_file', new_file])

if __name__ == "__main__":
    if len(argv) == 3 and argv[1] == 'process_file':
        process_file(argv[2])
    else:
        manager = Manager()
        while True:
            manager.scan_and_process()
            sleep(60)

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T19:21:06+00:00Added an answer on May 24, 2026 at 7:21 pm

    You don’t need threads for this becuase you’re already using subprocesses. Just let the subprocesses run and use Popen.poll() to check for completion.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a multithreaded application. I have a bunch of function that loop through a
I have a multithreaded application that has many concurrent operations going on at once.
I'm very new to Python and multithreaded programming in general. Basically, I have a
I have a multithreaded application written in C++. And I'm using mutex for file
I have a multithreaded server application that needs mutex locks over some shared memory.
I have a multithreaded WPF application that is using > 600 threads after is
I have a multithreaded .NET Windows Service that hangs intermittently -- maybe once every
Let's say I have a multithreaded C++ program that handles requests in the form
I have a graphical control that is multithreaded. Until now it worked fine, but
I have multithreaded application and I've got a little problem when application ends: I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.