#NEWLINE# def runPowerNotificationsThread( self ) : #NEWLINE# #INDENT# 'Main method of the spawned NSThread. Registers run loop source and runs current NSRunLoop.' #NEWLINE# pool = NSAutoreleasePool . alloc ( ) . init ( ) #NEWLINE# @ objc . callbackFor ( IOPSNotificationCreateRunLoopSource ) #NEWLINE# def on_power_source_notification( context ) : #NEWLINE# #INDENT# with self . _lock : #NEWLINE# #INDENT# for weak_observer in self . _weak_observers : #NEWLINE# #INDENT# observer = weak_observer ( ) #NEWLINE# if observer : #NEWLINE# #INDENT# observer . on_power_source_notification ( ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# self . _source = IOPSNotificationCreateRunLoopSource ( on_power_source_notification , None ) #NEWLINE# CFRunLoopAddSource ( NSRunLoop . currentRunLoop ( ) . getCFRunLoop ( ) , self . _source , kCFRunLoopDefaultMode ) #NEWLINE# while ( not NSThread . currentThread ( ) . isCancelled ( ) ) : #NEWLINE# #INDENT# NSRunLoop . currentRunLoop ( ) . runMode_beforeDate_ ( NSDefaultRunLoopMode , NSDate . distantFuture ( ) ) #NEWLINE# #UNINDENT# del pool