#NEWLINE# def add_callback( self , callback , * args , **kwargs ) : #NEWLINE# #INDENT# with self . _callback_lock : #NEWLINE# #INDENT# if self . _closing : #NEWLINE# #INDENT# raise RuntimeError ( 'IOLoop is closing' ) #NEWLINE# #UNINDENT# list_empty = ( not self . _callbacks ) #NEWLINE# self . _callbacks . append ( functools . partial ( stack_context . wrap ( callback ) , * args , ** kwargs ) ) #NEWLINE# if ( list_empty and ( thread . get_ident ( ) != self . _thread_ident ) ) : #NEWLINE# #INDENT# self . _waker . wake ( )