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 309655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:45:42+00:00 2026-05-12T07:45:42+00:00

I am currently using generators as a quick way to get the progress of

  • 0

I am currently using generators as a quick way to get the progress of long processes and I’m wondering how is it done usually as I find it not very elegant…

Let me explain first, I have a engine.py module that do some video processing (segmentation, bg/fg subtraction, etc) which takes a lot of time (from seconds to several minutes).

I use this module from a GUI written in wxpython and a console script.
When I looked at how to implement progress dialogs in wxpython, I saw that I must get somehow a progress value to update my dialog, which is pure logic you’ll admit…
So I decided to use the number of frame processed in my engine functions, yield the current frame number every 33 frames and yield None when the processing is finished.

by doing that here’s what it looks like:

dlg = wx.ProgressDialog("Movie processing", "Movie is being written...",
                           maximum = self.engine.endProcessingFrame,self.engine.startProcessingFrame,
                           parent=self,
                           style = wx.PD_APP_MODAL | wx.PD_ELAPSED_TIME | wx.PD_SMOOTH | wx.PD_CAN_ABORT)
state = self.engine.processMovie()
f = state.next()
while f != None:
    c, s = dlg.Update(f, "Processing frame %d"%f)
    if not c:break
    f = state.next()
dlg.Destroy()

That works very well, there is absolutely no noticeable speed loss, but I would like to be able to call processMovie() function without having to deal with generators if I don’t want to.

For instance my console script which uses the engine module doesn’t care of the progress, I could use it but it is destined to be executed in an environment where there is no display so I really don’t care about the progress…

Anyone with another design that the one I came up with? (using threads, globals, processes, etc)

There must be a design somewhere that does this job cleany I think 🙂

  • 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-12T07:45:42+00:00Added an answer on May 12, 2026 at 7:45 am

    Using a generator is fine for this, but the whole point of using generators is so you can builtin syntax:

    for f in self.engine.processMovie():
        c, s = dlg.Update(f, "Processing frame %d"%f)
        if not c: break
    

    If you don’t care about that, then you can either say:

    for f in self.engine.processMovie(): pass
    

    or expose a function (eg. engine.processMovieFull) to do that for you.

    You could also use a plain callback:

    def update_state(f):
        c, s = dlg.Update(f, "Processing frame %d"%f)
        return c
    self.engine.processMovie(progress=update_state)
    

    … but that’s not as nice if you want to process the data piecemeal; callback models prefer to do all the work at once–that’s the real benefit of generators.

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

Sidebar

Ask A Question

Stats

  • Questions 182k
  • Answers 182k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use timestamps or better yet audit tables to identify the… May 12, 2026 at 4:30 pm
  • Editorial Team
    Editorial Team added an answer Well, did you ever wish there were a module that… May 12, 2026 at 4:30 pm
  • Editorial Team
    Editorial Team added an answer Encapsulate it in a div with the following CSS attributes:… May 12, 2026 at 4:30 pm

Related Questions

I'm working on some code that generates a lot of ignoring return value of
I'm using DevExpress XtraReports in a WinForms application, but could equally apply to other
I am currently trying to implement an algorithm to select a unique (16-bit) identifier.
I am using NHibernate/Fluent NHibernate in an ASP.NET MVC app with a MySQL database.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.