ansible: make key_from_kwargs() 10x faster

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

@ -38,6 +38,7 @@ when a child has completed a job.
""" """
from __future__ import absolute_import from __future__ import absolute_import
import hashlib
import logging import logging
import os import os
import os.path import os.path
@ -114,11 +115,19 @@ class ContextService(mitogen.service.Service):
def key_from_kwargs(self, **kwargs): def key_from_kwargs(self, **kwargs):
""" """
Generate a deduplication key from the request. The default Generate a deduplication key from the request.
implementation returns a string based on a stable representation of the """
input dictionary generated by :py:func:`pprint.pformat`. out = []
""" stack = [kwargs]
return pprint.pformat(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): def _produce_response(self, key, response):
""" """

Loading…
Cancel
Save