Threading to keep gui alive

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Threading to keep gui alive

floatingshed
More Python than wxPython but it must be used a lot by folks here, so I thought this a good place to ask...

Whenever I need to run something in a new thread I have been using:
_thread.start_new_thread(self.my_method, (param,))

This is a hangover from Python2, now I am using Python3 exclusively I would like to update it using Threading. I have got this far:

class myThread (threading.Thread):
   
def __init__(self):
      threading
.Thread.__init__(self)


thread1
= myThread(self.my_method(param))
thread1
.start()

This runs my_method but apparently not in a new thread. Frankly I have no clue what I am doing!
Help! Please.

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Threading to keep gui alive

James Scholes
First of all, you don't need to subclass threading.Thread unless you're
going to add specific new functionality to a thread e.g. thread-local state.

Secondly, you're actually calling the method when you create the thread,
so the thread is being given the return value of the method to run as a
function instead of the method itself.  At that point, your method is
being called in the main thread.  Do this instead:

t = threading.Thread(target=self.my_method, args=(param,))
t.start()

Regards,

James Scholes
https://twitter.com/JamesScholes

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Threading to keep gui alive

floatingshed
In reply to this post by floatingshed
Thanks I will give that a try. I was following a basic tutorial at tutorialspoint.com which begins:

To implement a new thread using the threading module, you have to do the following −

  • Define a new subclass of the Thread class.



On Tuesday, December 5, 2017 at 12:53:52 PM UTC, [hidden email] wrote:
More Python than wxPython but it must be used a lot by folks here, so I thought this a good place to ask...

Whenever I need to run something in a new thread I have been using:
_thread.start_new_thread(self.my_method, (param,))

This is a hangover from Python2, now I am using Python3 exclusively I would like to update it using Threading. I have got this far:

class myThread (threading.Thread):
   
def __init__(self):
      threading
.Thread.__init__(self)


thread1
= myThread(self.my_method(param))
thread1
.start()

This runs my_method but apparently not in a new thread. Frankly I have no clue what I am doing!
Help! Please.

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Threading to keep gui alive

floatingshed
In reply to this post by floatingshed
Perfect! Thank you.

On Tuesday, December 5, 2017 at 12:53:52 PM UTC, [hidden email] wrote:
More Python than wxPython but it must be used a lot by folks here, so I thought this a good place to ask...

Whenever I need to run something in a new thread I have been using:
_thread.start_new_thread(self.my_method, (param,))

This is a hangover from Python2, now I am using Python3 exclusively I would like to update it using Threading. I have got this far:

class myThread (threading.Thread):
   
def __init__(self):
      threading
.Thread.__init__(self)


thread1
= myThread(self.my_method(param))
thread1
.start()

This runs my_method but apparently not in a new thread. Frankly I have no clue what I am doing!
Help! Please.

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Threading to keep gui alive

Rufus V. Smith
Please be careful how and which message you reply to, to keep the thread in context.

For example, the following exchange came into my email box, where you say "Perfect! Thank you." to
your own question, without forwarding the "Perfect" answer as well.

This does nothing to help the other readers of the thread, who would like to know
what the "Perfect" answer is.

I know this isn't the first time you've replied this way.  Can I respectfully request you
reply your thanks to the message that actually has the other emailer's solution in it?

Thanks.


On Dec 5, 2017, at 9:58 AM, [hidden email] wrote:

Perfect! Thank you.

On Tuesday, December 5, 2017 at 12:53:52 PM UTC, floati...@gmail.com wrote:
More Python than wxPython but it must be used a lot by folks here, so I thought this a good place to ask...

Whenever I need to run something in a new thread I have been using:
_thread.start_new_thread(self.my_method, (param,))

This is a hangover from Python2, now I am using Python3 exclusively I would like to update it using Threading. I have got this far:

class myThread (threading.Thread):
   
def __init__(self):
      threading
.Thread.__init__(self)


thread1
= myThread(self.my_method(param))
thread1
.start()

This runs my_method but apparently not in a new thread. Frankly I have no clue what I am doing!
Help! Please.

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.