How to stop the run function inside a subclass of Thread?

I was taking a look at a threading example here:

http://www.blog.pythonlibrary.org/2010/05/22/wxpython-and-threads/

Is there a way to stop the run function?

for i in range(6):

#if i == 3:

#destroy thread

time.sleep(10)

wx.CallAfter(self.postTime, i)

As a corollary, what would be the best way to stop the threaded process from running when someone closes the app? When I close wx.App the threaded process still runs in the background.

Your thread should check some condition, say self.continue on a regular basis and should have a halt or stop method that sets self.continue to False. If your main, thread starting code keeps handles to the threads it starts in an array called something like mythreads it can call
for t in mythreads:
    t.stop()
your threads should already post some information back when finished in the handler for that you also need to remove the thread that ended from the list.

Gadget/Steve

···

On 12/11/13 03:48, RedHotChiliPepper wrote:

I was taking a look at a threading example here:

wxPython and Threads - Mouse Vs Python

Is there a way to stop the run function?

for i in range(6):
    #if i == 3:
        #destroy thread
    time.sleep(10)
    wx.CallAfter(self.postTime, i)

As a corollary, what would be the best way to stop the threaded process from running when someone closes the app? When I close wx.App the threaded process still runs in the background.
--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Hmm so I tried this

for i in range(6):

if i == 3:

    self.continue = False

time.sleep(10)

wx.CallAfter(self.postTime, i)

And I get a syntax error.

I then changed def onButton(self, event):

def onButton(self, event):

"""

Runs the thread

"""

t = TestThread()

self.displayLbl.SetLabel("Thread started!")

btn = event.GetEventObject()

btn.Disable()

time.sleep(2)

t.stop()

And get the error AttributeError: ‘TestThread’ object has no attribute ‘stop’

Can you please advise?

···

On Tuesday, November 12, 2013 12:59:34 AM UTC-5, Gadget Steve wrote:

On 12/11/13 03:48, RedHotChiliPepper wrote:

I was taking a look at a threading example here:

http://www.blog.pythonlibrary.org/2010/05/22/wxpython-and-threads/

Is there a way to stop the run function?

for i in range(6):

#if i == 3:
    #destroy thread
time.sleep(10)
wx.CallAfter(self.postTime, i)

As a corollary, what would be the best way to stop the threaded
process from running when someone closes the app? When I close wx.App
the threaded process still runs in the background.


You received this message because you are subscribed to the Google
Groups “wxPython-users” group.

To unsubscribe from this group and stop receiving emails from it, send
an email to wxpython-user...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

Your thread should check some condition, say self.continue on a regular
basis and should have a halt or stop method that sets self.continue to
False. If your main, thread starting code keeps handles to the threads
it starts in an array called something like mythreads it can call

for t in mythreads:

t.stop()

your threads should already post some information back when finished in
the handler for that you also need to remove the thread that ended from
the list.

Gadget/Steve

I did say that it was stop()
The example at
calls it abort().

···

On 12/11/13 08:10, RedHotChiliPepper
wrote:

Hmm so I tried this

for i in range(6):

if i == 3:
                  self.continue

= False

time.sleep(10)

wx.CallAfter(self.postTime, i)

And I get a syntax error.

I then changed def
onButton(self, event):

            def onButton(self,

event):

"""
Runs the thread
"""
                t =

TestThread()

self.displayLbl.SetLabel(“Thread started!”)

                btn =

event.GetEventObject()

btn.Disable()
time.sleep(2)
t.stop()

And get the error AttributeError:
‘TestThread’ object has no attribute ‘stop’

Can you please advise?

up to you to implement
http://wiki.wxpython.org/LongRunningTasks