How to get a raised exception from other thread

Shitiz Bansal shitizb at yahoo.com
Sat Oct 15 02:32:34 CEST 2005


Threads can share the same memory space.
Hence a very neat way to achieve the objective.
 
> For example:
> 
> ---------------
> programA.py
> ---------------
> 
> import programB

Exception=0;<initialising a variable>

> thread = programB.MakeThread()
> thread.start()

if (Exception):
      raise SomeException()

> ---------------
> programB.py
> ---------------
> import threading, time
> 
> class SomeException(Exception):
> pass
> 
> class MakeThread(threading.Thread):
> def __init__(self):
> threading.Thread.__init__(self)
> 
> def run(self):
> i = 0
> while 1:
> print i
> i += 1
> time.sleep(1) #wait a second to continue
> if i>10:
 omit this ->raise SomeException()
instead:
 
if i>10:
Exception=1 or whatever
> 

Sounds cool?
 
shitiz

Jeremy Moles <jeremy at emperorlinux.com> wrote:
On non-Windows system there are a ton of ways to do it--this is almost a
whole field unto itself. :) (D-BUS, fifos, sockets, shmfs, etc.) In
Windows, I wouldn't have a clue. 

I guess this is a hard question to answer without a bit more
information. :)

On Fri, 2005-10-14 at 14:45 -0700, dcrespo wrote:
> Hi all,
> 
> How can I get a raised exception from other thread that is in an
> imported module?
> 
> For example:
> 
> ---------------
> programA.py
> ---------------
> 
> import programB
> 
> thread = programB.MakeThread()
> thread.start()
> 
> ---------------
> programB.py
> ---------------
> import threading, time
> 
> class SomeException(Exception):
> pass
> 
> class MakeThread(threading.Thread):
> def __init__(self):
> threading.Thread.__init__(self)
> 
> def run(self):
> i = 0
> while 1:
> print i
> i += 1
> time.sleep(1) #wait a second to continue
> if i>10:
> raise SomeException()
> 
> 
> Thanks
> 
> Daniel
> 

-- 
http://mail.python.org/mailman/listinfo/python-list





		
---------------------------------
 Yahoo! Music Unlimited - Access over 1 million songs. Try it free.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20051014/bd452024/attachment.html>


More information about the Python-list mailing list