Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ExpiringDict objects cant be pickled by Dill - but OrderedDict can be pickled !!! #35

Open
bitranox opened this issue Apr 2, 2019 · 1 comment

Comments

@bitranox
Copy link
Contributor

bitranox commented Apr 2, 2019

In order to use that objects together with wrapt_timeout_decorator
https://github.com/bitranox/wrapt_timeout_decorator

it needs to be pickable - but it is not.
Ordered Dict can be pickled.

Test Code :

from expiringdict import ExpiringDict
import dill

try:
    from collections import OrderedDict
except ImportError:
    # Python < 2.7
    from ordereddict import OrderedDict


def test_pickle_ordered_dict():
    """
    >>> # test to pickle ordered dict
    >>> dict_test=OrderedDict()
    >>> dict_test['test'] = 1
    >>> pickled_object = dill.dumps(dict_test)
    >>> original_object = dill.loads(pickled_object)
    >>> original_object['test']
    1
    """
    pass


def test_pickle_expiring_dict():
    """
    >>> # test to pickle ordered dict
    >>> dict_test=ExpiringDict(max_len=200000, max_age_seconds=1800)
    >>> dict_test['test'] = 1
    >>> pickled_object = dill.dumps(dict_test)
    >>> original_object = dill.loads(pickled_object)  # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
    Traceback (most recent call last):
    ...
    TypeError: __init__() missing 2 required positional arguments: 'max_len' and 'max_age_seconds'

    """
    pass


def test_pickle_expiring_dict_pass():
    """
    >>> # test to pickle ordered dict
    >>> dict_test=ExpiringDict(max_len=200*1E3, max_age_seconds=30*60)
    >>> dict_test['test'] = 1
    >>> dict_test_pickable = OrderedDict(dict_test)
    >>> pickled_object = dill.dumps(dict_test_pickable)
    >>> original_object = dill.loads(pickled_object)  # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
    >>> original_object['test']
    1

    """
    pass


def main():
    pass


if __name__ == "__main__":
    main()
@bitranox
Copy link
Contributor Author

bitranox commented Apr 3, 2019

I extended the Class to make it pickable and added some copy functions.
Just look at #36

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant