#NEWLINE# @ synchronized ( 'arbiter_reload_config' ) #NEWLINE# @ gen . coroutine #NEWLINE# def reload_from_config( self , config_file = None , inside_circusd = False ) : #NEWLINE# #INDENT# new_cfg = get_config ( ( config_file if config_file else self . config_file ) ) #NEWLINE# if ( self . get_arbiter_config ( new_cfg ) != self . _cfg ) : #NEWLINE# #INDENT# ( yield self . _restart ( inside_circusd = inside_circusd ) ) #NEWLINE# return #NEWLINE# #UNINDENT# ignore_sn = set ( [ 'circushttpd' ] ) #NEWLINE# ignore_wn = set ( [ 'circushttpd' , 'circusd-stats' ] ) #NEWLINE# current_sn = ( set ( [ i . name for i in self . sockets . values ( ) ] ) - ignore_sn ) #NEWLINE# new_sn = set ( [ i [ 'name' ] for i in new_cfg . get ( 'sockets' , [ ] ) ] ) #NEWLINE# added_sn = ( new_sn - current_sn ) #NEWLINE# deleted_sn = ( current_sn - new_sn ) #NEWLINE# maybechanged_sn = ( current_sn - deleted_sn ) #NEWLINE# changed_sn = set ( [ ] ) #NEWLINE# wn_with_changed_socket = set ( [ ] ) #NEWLINE# wn_with_deleted_socket = set ( [ ] ) #NEWLINE# for n in maybechanged_sn : #NEWLINE# #INDENT# s = self . get_socket ( n ) #NEWLINE# if ( self . get_socket_config ( new_cfg , n ) != s . _cfg ) : #NEWLINE# #INDENT# changed_sn . add ( n ) #NEWLINE# deleted_sn . add ( n ) #NEWLINE# added_sn . add ( n ) #NEWLINE# for w in self . iter_watchers ( ) : #NEWLINE# #INDENT# if ( ( 'circus.sockets.%s' % n . lower ( ) ) in w . cmd ) : #NEWLINE# #INDENT# wn_with_changed_socket . add ( w . name ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# for n in deleted_sn : #NEWLINE# #INDENT# s = self . get_socket ( n ) #NEWLINE# s . close ( ) #NEWLINE# for w in self . iter_watchers ( ) : #NEWLINE# #INDENT# if ( ( 'circus.sockets.%s' % n . lower ( ) ) in w . cmd ) : #NEWLINE# #INDENT# wn_with_deleted_socket . add ( w . name ) #NEWLINE# #UNINDENT# #UNINDENT# del self . sockets [ s . name ] #NEWLINE# #UNINDENT# for n in added_sn : #NEWLINE# #INDENT# socket_config = self . get_socket_config ( new_cfg , n ) #NEWLINE# s = CircusSocket . load_from_config ( socket_config ) #NEWLINE# s . bind_and_listen ( ) #NEWLINE# self . sockets [ s . name ] = s #NEWLINE# #UNINDENT# if ( added_sn or deleted_sn ) : #NEWLINE# #INDENT# for watcher in self . iter_watchers ( ) : #NEWLINE# #INDENT# watcher . initialize ( self . evpub_socket , self . sockets , self ) #NEWLINE# #UNINDENT# #UNINDENT# current_wn = ( set ( [ i . name for i in self . iter_watchers ( ) ] ) - ignore_wn ) #NEWLINE# new_wn = set ( [ i [ 'name' ] for i in new_cfg . get ( 'watchers' , [ ] ) ] ) #NEWLINE# new_wn = ( new_wn | set ( [ i [ 'name' ] for i in new_cfg . get ( 'plugins' , [ ] ) ] ) ) #NEWLINE# added_wn = ( ( new_wn - current_wn ) | wn_with_changed_socket ) #NEWLINE# deleted_wn = ( ( current_wn - new_wn ) - wn_with_changed_socket ) #NEWLINE# maybechanged_wn = ( current_wn - deleted_wn ) #NEWLINE# changed_wn = set ( [ ] ) #NEWLINE# if ( wn_with_deleted_socket and ( wn_with_deleted_socket not in new_wn ) ) : #NEWLINE# #INDENT# raise ValueError ( ( 'Watchers %s uses a socket which is deleted' % wn_with_deleted_socket ) ) #NEWLINE# #UNINDENT# for n in maybechanged_wn : #NEWLINE# #INDENT# w = self . get_watcher ( n ) #NEWLINE# new_watcher_cfg = ( self . get_watcher_config ( new_cfg , n ) or self . get_plugin_config ( new_cfg , n ) ) #NEWLINE# old_watcher_cfg = w . _cfg . copy ( ) #NEWLINE# if ( 'env' in new_watcher_cfg ) : #NEWLINE# #INDENT# new_watcher_cfg [ 'env' ] = parse_env_dict ( new_watcher_cfg [ 'env' ] ) #NEWLINE# #UNINDENT# for key in _ENV_EXCEPTIONS : #NEWLINE# #INDENT# if ( ( 'env' in new_watcher_cfg ) and ( key in new_watcher_cfg [ 'env' ] ) ) : #NEWLINE# #INDENT# del new_watcher_cfg [ 'env' ] [ key ] #NEWLINE# #UNINDENT# if ( ( 'env' in new_watcher_cfg ) and ( key in old_watcher_cfg [ 'env' ] ) ) : #NEWLINE# #INDENT# del old_watcher_cfg [ 'env' ] [ key ] #NEWLINE# #UNINDENT# #UNINDENT# diff = DictDiffer ( new_watcher_cfg , old_watcher_cfg ) . changed ( ) #NEWLINE# if ( diff == set ( [ 'numprocesses' ] ) ) : #NEWLINE# #INDENT# w . set_numprocesses ( int ( new_watcher_cfg [ 'numprocesses' ] ) ) #NEWLINE# changed = False #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# changed = ( len ( diff ) > 0 ) #NEWLINE# #UNINDENT# if changed : #NEWLINE# #INDENT# changed_wn . add ( n ) #NEWLINE# deleted_wn . add ( n ) #NEWLINE# added_wn . add ( n ) #NEWLINE# #UNINDENT# #UNINDENT# for n in deleted_wn : #NEWLINE# #INDENT# w = self . get_watcher ( n ) #NEWLINE# ( yield w . _stop ( ) ) #NEWLINE# del self . _watchers_names [ w . name . lower ( ) ] #NEWLINE# self . watchers . remove ( w ) #NEWLINE# #UNINDENT# for n in added_wn : #NEWLINE# #INDENT# new_watcher_cfg = ( self . get_plugin_config ( new_cfg , n ) or self . get_watcher_config ( new_cfg , n ) ) #NEWLINE# w = Watcher . load_from_config ( new_watcher_cfg ) #NEWLINE# w . initialize ( self . evpub_socket , self . sockets , self ) #NEWLINE# ( yield self . start_watcher ( w ) ) #NEWLINE# self . watchers . append ( w ) #NEWLINE# self . _watchers_names [ w . name . lower ( ) ] = w