Re: [Pyobjc-dev] Kill Thread on Exception
Brought to you by:
ronaldoussoren
|
From: Koen B. <ko...@ma...> - 2008-02-09 22:45:36
|
Hey Ronald, I am playing around with this and it seems to work. But how can I make all my NSObjects to add this method? I tried importing this in AppName.py but the methods do not get added to underlying modules. Do I need to import this wherever I use it after importing any other classes based on NSObject? If anyone runs into the same get the script here: http://pastie.caboo.se/149814 Koen On 28 jan 2008, at 14:23, Ronald Oussoren wrote: > > On Monday, January 28, 2008, at 01:04PM, "Koen Bok" <ko...@ma... > > wrote: >> I guess I have to do it that way. Could you supply me with some >> hints/ >> directions how to start this? >> >> Thanks a lot, > > Something like this should do the trick: > > class NSObject (objc.Category(NSObject)): > def _pyobjc_performOnThread_(self, callinfo): > try: > sel, arg = callinfo > m = self.methodForSelector_(sel) > m(arg) > except: import traceback > traceback.print_exc() > _pyobjc_performOnThread = _objc.selector(_pyobjc_performOnThread, > sel="_pyobjc_performOnThread:") > > def pyobjc_performSelector_onThread_withObject_waitUntilDone_( > self, aSelector, thread, arg, wait): > """ > A version of > performSelector:onThread:withObject:waitUntilDone: that > will log exceptions in the called method (instead of aborting > the > NSRunLoop on the other thread). > """ > self.performSelector_onThread_withObject_waitUntilDone_( > 'pyobjc_performOnThread:', thread, (aSelector, arg), > wait) > > > This is completely untested, but should do the trick, you can then > use pyobjc_performSelector_onThread_withObject_waitUntilDone_ > instead of the version without pyobjc_ prefix. > > This would be a good addition for PyObjC 2.1 (at least when the > other variants of performSelector are added as well). > > Ronald >> >> Koen >> >> >> On 27 jan 2008, at 18:21, Ronald Oussoren wrote: >> >>> There's not much you can do about this, the cleanest way to avoid >>> stopping your application is to add you're own method for executing >>> code on the main loop and have that catch all exceptions. This can >>> easily be build on top of the NSObject version. >> >> >> ------------------------------------------------------------------------- >> This SF.net email is sponsored by: Microsoft >> Defy all challenges. Microsoft(R) Visual Studio 2008. >> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ >> _______________________________________________ >> Pyobjc-dev mailing list >> Pyo...@li... >> https://lists.sourceforge.net/lists/listinfo/pyobjc-dev >> >> |