ansible: make key_from_kwargs() 10x faster

It was half the cost of the service call
pull/228/head
David Wilson 6 years ago
parent 79c2d6c289
commit 95039eea11

@ -38,6 +38,7 @@ when a child has completed a job.
"""
from __future__ import absolute_import
import hashlib
import logging
import os
import os.path
@ -114,11 +115,19 @@ class ContextService(mitogen.service.Service):
def key_from_kwargs(self, **kwargs):
"""
Generate a deduplication key from the request. The default
implementation returns a string based on a stable representation of the
input dictionary generated by :py:func:`pprint.pformat`.
"""
return pprint.pformat(kwargs)
Generate a deduplication key from the request.
"""
out = []
stack = [kwargs]
while stack:
obj = stack.pop()
if isinstance(obj, dict):
stack.extend(sorted(obj.iteritems()))
elif isinstance(obj, (list, tuple)):
stack.extend(obj)
else:
out.append(str(obj))
return ''.join(out)
def _produce_response(self, key, response):
"""

Loading…
Cancel
Save