Merge pull request #36310 from thatch45/keep_loop

Fix bug where the client will destroy the loop
This commit is contained in:
Mike Place 2016-09-20 22:14:23 +09:00 committed by GitHub
commit d0a495f08b
2 changed files with 26 additions and 9 deletions

View File

@ -126,7 +126,7 @@ class LocalClient(object):
def __init__(self, def __init__(self,
c_path=os.path.join(syspaths.CONFIG_DIR, 'master'), c_path=os.path.join(syspaths.CONFIG_DIR, 'master'),
mopts=None, skip_perm_errors=False, mopts=None, skip_perm_errors=False,
io_loop=None): io_loop=None, keep_loop=False):
''' '''
:param IOLoop io_loop: io_loop used for events. :param IOLoop io_loop: io_loop used for events.
Pass in an io_loop if you want asynchronous Pass in an io_loop if you want asynchronous
@ -155,7 +155,8 @@ class LocalClient(object):
self.opts['transport'], self.opts['transport'],
opts=self.opts, opts=self.opts,
listen=False, listen=False,
io_loop=io_loop) io_loop=io_loop,
keep_loop=keep_loop)
self.utils = salt.loader.utils(self.opts) self.utils = salt.loader.utils(self.opts)
self.functions = salt.loader.minion_mods(self.opts, utils=self.utils) self.functions = salt.loader.minion_mods(self.opts, utils=self.utils)
self.returners = salt.loader.returners(self.opts, self.functions) self.returners = salt.loader.returners(self.opts, self.functions)

View File

@ -112,7 +112,7 @@ TAGS = {
def get_event( def get_event(
node, sock_dir=None, transport='zeromq', node, sock_dir=None, transport='zeromq',
opts=None, listen=True, io_loop=None): opts=None, listen=True, io_loop=None, keep_loop=False):
''' '''
Return an event object suitable for the named transport Return an event object suitable for the named transport
@ -125,8 +125,8 @@ def get_event(
# TODO: AIO core is separate from transport # TODO: AIO core is separate from transport
if transport in ('zeromq', 'tcp'): if transport in ('zeromq', 'tcp'):
if node == 'master': if node == 'master':
return MasterEvent(sock_dir, opts, listen=listen, io_loop=io_loop) return MasterEvent(sock_dir, opts, listen=listen, io_loop=io_loop, keep_loop=keep_loop)
return SaltEvent(node, sock_dir, opts, listen=listen, io_loop=io_loop) return SaltEvent(node, sock_dir, opts, listen=listen, io_loop=io_loop, keep_loop=keep_loop)
elif transport == 'raet': elif transport == 'raet':
import salt.utils.raetevent import salt.utils.raetevent
return salt.utils.raetevent.RAETEvent(node, return salt.utils.raetevent.RAETEvent(node,
@ -177,14 +177,19 @@ class SaltEvent(object):
''' '''
def __init__( def __init__(
self, node, sock_dir=None, self, node, sock_dir=None,
opts=None, listen=True, io_loop=None): opts=None, listen=True, io_loop=None, keep_loop=False):
''' '''
:param IOLoop io_loop: Pass in an io_loop if you want asynchronous :param IOLoop io_loop: Pass in an io_loop if you want asynchronous
operation for obtaining events. Eg use of operation for obtaining events. Eg use of
set_event_handler() API. Otherwise, operation set_event_handler() API. Otherwise, operation
will be synchronous. will be synchronous.
:param Bool keep_loop: Pass a boolean to determine if we want to keep
the io loop or destroy it when the event handle
is destroyed. This is useful when using event
loops from within third party async code
''' '''
self.serial = salt.payload.Serial({'serial': 'msgpack'}) self.serial = salt.payload.Serial({'serial': 'msgpack'})
self.keep_loop = keep_loop
if io_loop is not None: if io_loop is not None:
self.io_loop = io_loop self.io_loop = io_loop
self._run_io_loop_sync = False self._run_io_loop_sync = False
@ -687,7 +692,7 @@ class SaltEvent(object):
self.subscriber.close() self.subscriber.close()
if self.pusher is not None: if self.pusher is not None:
self.pusher.close() self.pusher.close()
if self._run_io_loop_sync: if self._run_io_loop_sync and not self.keep_loop:
self.io_loop.close() self.io_loop.close()
def fire_ret_load(self, load): def fire_ret_load(self, load):
@ -750,9 +755,20 @@ class MasterEvent(SaltEvent):
RAET compatible RAET compatible
Create a master event management object Create a master event management object
''' '''
def __init__(self, sock_dir, opts=None, listen=True, io_loop=None): def __init__(
self,
sock_dir,
opts=None,
listen=True,
io_loop=None,
keep_loop=False):
super(MasterEvent, self).__init__( super(MasterEvent, self).__init__(
'master', sock_dir, opts, listen=listen, io_loop=io_loop) 'master',
sock_dir,
opts,
listen=listen,
io_loop=io_loop,
keep_loop=keep_loop)
class LocalClientEvent(MasterEvent): class LocalClientEvent(MasterEvent):