More control on thread

hi all,

I have adapted this demo from an example that I have found on wxPython in Action (always saint was who wrote it) because I need to cyclically read some files from a directory.

To the start button I read the names of the files of the current directory and I write them on the wx.TextCtrl together with my sentinel value self.check.

When I press the stop button I would expect me that the thread was stopped immediately, instead the reading/writing engages continuous even if the value of self.check correctly changes to False.

Besides, when I close the frame I control before if the thread is active (isAlive()) but happens it(the frame) enters a catatonic state…I’m on debian.

In practice I would expect me that when I set self.check to False the thread was more responsivos.

what I am wrong in the approach?

suggestions?

beppe

simple_app.py (2.32 KB)

You only test self.check once you're done printing all the files in
the current directory. If there's a lot of files this can take a long
time. Add this immediately after "for file_name in
os.listdir(directory)":

                    if not self.check:
                        break

-Chris

···

On Mon, Sep 10, 2012 at 7:36 AM, beppe <giuseppecostanzi@gmail.com> wrote:

hi all,
I have adapted this demo from an example that I have found on wxPython in
Action (always saint was who wrote it) because I need to cyclically read
some files from a directory.

To the start button I read the names of the files of the current directory
and I write them on the wx.TextCtrl together with my sentinel value
self.check.

When I press the stop button I would expect me that the thread was stopped
immediately, instead the reading/writing engages continuous even if the
value of self.check correctly changes to False.

perfect, thanks.

···

Il giorno lunedì 10 settembre 2012 17:07:44 UTC+2, Chris ha scritto:

On Mon, Sep 10, 2012 at 7:36 AM, beppe giuseppe...@gmail.com wrote:

hi all,

I have adapted this demo from an example that I have found on wxPython in

Action (always saint was who wrote it) because I need to cyclically read

some files from a directory.

To the start button I read the names of the files of the current directory

and I write them on the wx.TextCtrl together with my sentinel value

self.check.

When I press the stop button I would expect me that the thread was stopped

immediately, instead the reading/writing engages continuous even if the

value of self.check correctly changes to False.

You only test self.check once you’re done printing all the files in

the current directory. If there’s a lot of files this can take a long

time. Add this immediately after "for file_name in

os.listdir(directory)":

                if not self.check:

                    break

-Chris