def detach(self): assert self.state == CaptureState.ATTACHED session = self.session script = self.script self.session = None self.script = None self._updateState_(CaptureState.DETACHED) NSThread.detachNewThreadSelector_toTarget_withObject_('_doDetachWithParams:', self, (session, script))
def applicationShouldTerminate_(self, sender): BlinkLogger().log_info('Application will terminate') NSThread.detachNewThreadSelector_toTarget_withObject_("killSelfAfterTimeout:", self, None) NotificationCenter().post_notification("BlinkShouldTerminate", None) NotificationCenter().add_observer(self, name="SIPApplicationDidEnd") SIPApplication().stop() return NSTerminateLater
def applicationShouldTerminate_(self, sender): if self.terminating: return True self.terminating = True BlinkLogger().log_info('Application will be terminated') NSThread.detachNewThreadSelector_toTarget_withObject_("killSelfAfterTimeout:", self, None) NotificationCenter().post_notification("BlinkShouldTerminate", None) NotificationCenter().add_observer(self, name="SIPApplicationDidEnd") app = SIPApplication() app.stop() import Profiler Profiler.stop(os.path.join(ApplicationData.directory, 'logs', 'profiler.stats')) return False
def delegate(cls): if not NSThread.isMainThread(): thread = threading.current_thread() pool = getattr(thread, 'ns_autorelease_pool', None) if pool is None: print("--- calling NSApp.delegate() without an autorelease pool from {}".format(thread)) traceback.print_stack() return NSApp.delegate()
def call_in_gui_thread(func, *args, **kwargs): if NSThread.isMainThread(): func(*args, **kwargs) else: pool = NSAutoreleasePool.alloc().init() NSApp.delegate().performSelectorOnMainThread_withObject_waitUntilDone_( "callObject:", lambda: func(*args, **kwargs), False) del pool
def refreshWithSender_(self, sender): if self.crawlTask is not None: return self.stopRefreshWithSender_(sender) logger.debug('%r refreshWithSender:%r', self, sender) sender.setImage_(NSImage.imageNamed_(NSImageNameStopProgressTemplate)) self.crawlTask = NSThread.alloc().initWithTarget_selector_object_( self, 'crawlWithSender:', sender ) self.crawlTask.start()
def performCall(self): """ Actually runs the payload. """ assert NSThread.isMainThread(), "Call is not executing on the Main thread!" # Unpack the payload. (func, args, kwargs) = self._payload # Run it. func(*args, **kwargs)
def scheduleCallWithDelay_(self, delay): """ This is run once we're on the Main thread. """ assert NSThread.isMainThread(), "Call is not executing on the Main thread!" # There's no delay, just run the call now. if not delay: self.performCall() return # There's a delay, schedule it for later. self.performSelector_withObject_afterDelay_(self.performCall, None, delay)
def scheduleCallWithDelay_(self, delay): """ This is run once we're on the Main thread. """ assert NSThread.isMainThread(), "Call is not executing on the Main thread!" # There's no delay, just run the call now. if not delay: self.performCall() return # There's a delay, schedule it for later. self.performSelector_withObject_afterDelay_( self.performCall, None, delay, )
def _post(self, message): NSThread.detachNewThreadSelector_toTarget_withObject_( '_doPostWithParams:', self, (self.script, message))
def attachToProcess_triggerPort_(self, process, triggerPort): assert self.state == CaptureState.DETACHED self._updateState_(CaptureState.ATTACHING) NSThread.detachNewThreadSelector_toTarget_withObject_( '_doAttachWithParams:', self, (process.pid, triggerPort))
def _post(self, message): NSThread.detachNewThreadSelector_toTarget_withObject_('_doPostWithParams:', self, (self.script, message))
def attachToProcess_triggerPort_(self, process, triggerPort): assert self.state == CaptureState.DETACHED self._updateState_(CaptureState.ATTACHING) NSThread.detachNewThreadSelector_toTarget_withObject_('_doAttachWithParams:', self, (process.pid, triggerPort))
def call_in_gui_thread(func, *args, **kwargs): if NSThread.isMainThread(): func(*args, **kwargs) else: NSApp.delegate().performSelectorOnMainThread_withObject_waitUntilDone_("callObject:", lambda: func(*args, **kwargs), False)
def wrapper(*args, **kw): if NSThread.isMainThread(): func(*args, **kw) else: NSApp.delegate().performSelectorOnMainThread_withObject_waitUntilDone_("callObject:", lambda: func(*args, **kw), False)