def wait_for_event(self, **event_args):
# Demented python scope.
# http://stackoverflow.com/questions/4851463/python-closure-write-to-variable-in-parent-scope
# This variable could be an object, but instead it's a single-element list.
event_matched = []
@gen.coroutine
def mark_true(event):
event_matched.append(event)
log.info('Creating a temporary listener for %s' % (event_args,))
self.event_listeners.append((event_args, mark_true))
while not event_matched:
yield gen.moment
log.info('Deleting the temporary listener for %s' % (event_args,))
self.event_listeners.remove((event_args, mark_true))
raise gen.Return(event_matched[0])
评论列表
文章目录