diff --git a/ansible_mitogen/services.py b/ansible_mitogen/services.py index ae6e8ed7..57f19ebd 100644 --- a/ansible_mitogen/services.py +++ b/ansible_mitogen/services.py @@ -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): """