Re: Thread terminate

2014-08-28 Thread Ervin Hegedüs
Hi Chris, thanks for the reply, On Wed, Aug 27, 2014 at 12:26:48PM -0700, Chris Kaynor wrote: On Wed, Aug 27, 2014 at 11:55 AM, Ervin Hegedüs airw...@gmail.com wrote: what's the correct way to terminate a thread by itself? To terminate the thread, the run function must exit. This can

Re: Thread terminate

2014-08-28 Thread Marko Rauhamaa
Ervin Hegedüs airw...@gmail.com: at this time there is only one thread, as you wrote. I just try to prepare it to higher load, when one thread will not enough... Threads are a necessary evil when dealing with blocking function calls, but evil they remain. I would generally *not* associate a

Re: Thread terminate

2014-08-28 Thread Ervin Hegedüs
Hi Marko, On Thu, Aug 28, 2014 at 12:02:29PM +0300, Marko Rauhamaa wrote: Ervin Hegedüs airw...@gmail.com: at this time there is only one thread, as you wrote. I just try to prepare it to higher load, when one thread will not enough... Threads are a necessary evil when dealing with

Re: Thread terminate

2014-08-28 Thread Skip Montanaro
On Wed, Aug 27, 2014 at 1:55 PM, Ervin Hegedüs airw...@gmail.com wrote: what's the correct way to terminate a thread by itself? If this is something you need to do as a regular course of business, I'd share a Queue between the main thread and the target thread. When you want it to exit, shoot

Re: Thread terminate

2014-08-28 Thread Chris Kaynor
On Thu, Aug 28, 2014 at 1:52 AM, Ervin Hegedüs airw...@gmail.com wrote: In your case, you may want to just handle the exceptions inside the thread's run() function directly. If that is not possible and you really need to handle them inside the main thread, you would need to store off the

Re: Thread terminate

2014-08-28 Thread Chris Angelico
On Fri, Aug 29, 2014 at 2:23 AM, Chris Kaynor ckay...@zindagigames.com wrote: If what you want is to make sure the error is not printed to stderr, you'll just need to make sure the thread's run function does not exit with an exception. The simpliest way to do that would be to wrap the entire

Re: Thread terminate

2014-08-28 Thread Ervin Hegedüs
Hi Chris, thanks for you answer, On Thu, Aug 28, 2014 at 09:23:24AM -0700, Chris Kaynor wrote: On Thu, Aug 28, 2014 at 1:52 AM, Ervin Hegedüs airw...@gmail.com wrote: In your case, you may want to just handle the exceptions inside the thread's run() function directly. If that is not

Re: Thread terminate

2014-08-28 Thread Chris Kaynor
On Thu, Aug 28, 2014 at 11:39 AM, Ervin Hegedüs airw...@gmail.com wrote: Hi Chris, thanks for you answer, On Thu, Aug 28, 2014 at 09:23:24AM -0700, Chris Kaynor wrote: On Thu, Aug 28, 2014 at 1:52 AM, Ervin Hegedüs airw...@gmail.com wrote: In your case, you may want to just handle

Re: Thread terminate

2014-08-28 Thread Ervin Hegedüs
Hi Chris, On Thu, Aug 28, 2014 at 12:34:18PM -0700, Chris Kaynor wrote: On Thu, Aug 28, 2014 at 11:39 AM, Ervin Hegedüs airw...@gmail.com wrote: now the code looks like this: def run(self): try: connect_to_db() except: self._exit(-1, Connection error,

Re: Thread terminate

2014-08-28 Thread Chris Kaynor
On Thu, Aug 28, 2014 at 1:35 PM, Ervin Hegedüs airw...@gmail.com wrote: On Thu, Aug 28, 2014 at 12:34:18PM -0700, Chris Kaynor wrote: depending on what you are doing with the first two arguments to self._exit, the following might also work: def run(self): try: connect_to_db()

Re: Thread terminate

2014-08-28 Thread Cameron Simpson
On 28Aug2014 12:02, Marko Rauhamaa ma...@pacujo.net wrote: Ervin Hegedüs airw...@gmail.com: at this time there is only one thread, as you wrote. I just try to prepare it to higher load, when one thread will not enough... Threads are a necessary evil when dealing with blocking function calls,

Thread terminate

2014-08-27 Thread Ervin Hegedüs
Hi, what's the correct way to terminate a thread by itself? I mean: class MyThread(threading.Thread): def __init__(self, queueitem): threading.Thread.__init__(self) ... def run(self): pseudo code below try: self.connect_to_database()

Re: Thread terminate

2014-08-27 Thread Chris Kaynor
On Wed, Aug 27, 2014 at 11:55 AM, Ervin Hegedüs airw...@gmail.com wrote: what's the correct way to terminate a thread by itself? To terminate the thread, the run function must exit. This can be either from an exception or a return statement. I mean: class MyThread(threading.Thread):