Hello,
consider the following code:
<module1>
import sys
import threading
class MyException(Exc eption):
pass
#from module1 import MyException
class runner(threadin g.Thread):
def __init__(self, callableObj):
self.callableOb ject=callableOb j
threading.Threa d.__init__(self )
def run(self):
try:
self.callableOb ject.makeCall()
except MyException, err:
print "MyExceptio n"
print sys.exc_type, err
except Exception, err:
print "Exception"
print sys.exc_type, err
if __name__ == '__main__':
if len(sys.argv) != 3:
print "Usage <module> <class>"
else:
callableObj = getattr(__impor t__(sys.argv[1]), sys.argv[2])()
thread=runner(c allableObj)
thread.start()
</module1>
<module2>
from module1 import MyException
class Callable:
def makeCall(self):
raise MyException("My Exception")
</module2>
Now I start the process:
python module1.py module2 Callable
And the result is:
Exception
module1.MyExcep tion MyException
So the Exception isn't recognised even though it has the same
namespace and name as the exception defined in the module. I have to
uncomment the 7th line to get my example to behave as I would like it
to.
Is this a bug/feature? Is there any reason why it shouldn't work the
way I expect it to?
Regards,
Sam Owen
consider the following code:
<module1>
import sys
import threading
class MyException(Exc eption):
pass
#from module1 import MyException
class runner(threadin g.Thread):
def __init__(self, callableObj):
self.callableOb ject=callableOb j
threading.Threa d.__init__(self )
def run(self):
try:
self.callableOb ject.makeCall()
except MyException, err:
print "MyExceptio n"
print sys.exc_type, err
except Exception, err:
print "Exception"
print sys.exc_type, err
if __name__ == '__main__':
if len(sys.argv) != 3:
print "Usage <module> <class>"
else:
callableObj = getattr(__impor t__(sys.argv[1]), sys.argv[2])()
thread=runner(c allableObj)
thread.start()
</module1>
<module2>
from module1 import MyException
class Callable:
def makeCall(self):
raise MyException("My Exception")
</module2>
Now I start the process:
python module1.py module2 Callable
And the result is:
Exception
module1.MyExcep tion MyException
So the Exception isn't recognised even though it has the same
namespace and name as the exception defined in the module. I have to
uncomment the 7th line to get my example to behave as I would like it
to.
Is this a bug/feature? Is there any reason why it shouldn't work the
way I expect it to?
Regards,
Sam Owen
Comment