Monitoring updating directory for image for GUI

Oscar Benjamin oscar.j.benjamin at gmail.com
Thu Feb 7 21:01:04 EST 2013


On 8 February 2013 00:48,  <ciscorucinski at gmail.com> wrote:
> Real-time...as close to real-time as possible. That is why I did not really want to use a queue. That is because if a bunch of the thread that create the images finish really close to one another (when they should be spread out based on how the music is played), then there would be a larger "lag" in the display. So displaying only the most recent image is preferred.

Who/what are you responding to here? You haven't included any context
from what you're replying to.

> That is why I though Stack...but then that might mean that older images will replace newer ones.
>
> The Workflow is as such:
>
> 1) Music is analyzed and streamed to the program. Note-by-Note.
> 2) The note is grabbed (same way as a Java Scanner class)
> 3) A new thread is created to call an OS command (Lilypond command)
>    a) Thread waits until command is finished, and Lilypond creates an image that I can define the filename for in a directory.
>
> From here I want only the latest one (as close to the latest one at least) to be displayed to the gtkImage object in the GUI

So you have a thread that updates the image and then checks the stack
to see if a new image is available? Can you not just have it only try
to load the newest image?

You say that you control the filenames of the images. I assume that
you are notified when a file is created and given the filename of the
new file. So you can maintain a mapping of filename->ordering. In this
case you can determine when a file notification arrives whether the
filename corresponds to a more recent note than the filename that is
currently waiting to be displayed (or is currently displayed). If it
is an older note then discard it (and delete the file?) when the
notification arrives. If it is newer then discard the one that is
currently waiting to be displayed. This way there are always either
zero or one filenames waiting and if there is one then it is the most
recent one seen so far.

> I set up a class that would act as a directory monitor (just stubbed)...that would do all the work I am asking for here

Is that using something like watchdog?
http://pypi.python.org/pypi/watchdog

>
> Also, don't think this matters much, but I am using Windows (I seen someone mention Linux)

It matters for how you monitor the directory at least.


Oscar



More information about the Python-list mailing list