question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

wrapt functions are not dill-able

See original GitHub issue

It would be extremely useful if wrapt functions were serializable in some way. Although pickle support is unlikely given that pickle doesn’t even handle undecorated functions, I hoped the more capable dill may have been up to the task, as dill is capable of handling the decorator pattern in general:

def basic_pass_through(f):

    def g(*args, **kwargs):
        return f(*args, **kwargs)

    return g

@basic_pass_through
def basic_function(a):
    return 2 * a

import dill
f_str = dill.dumps(basic_function)
function_back = dill.loads(f_str)

assert function_back(2) == 4

unfortunately, with wrapt we get:

import wrapt

@wrapt.decorator
def pass_through(wrapped, instance, args, kwargs):
    return wrapped(*args, **kwargs)

@pass_through
def function():
    pass

import dill
f_str = dill.dumps(function)
function_back = dill.loads(f_str)

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-1-f472b826a7de> in <module>()
     13 
     14 f_str = dill.dumps(function)
---> 15 function_back = dill.loads(f_str)

.../lib/python2.7/site-packages/dill/dill.pyc in loads(str)
    158     """unpickle an object from a string"""
    159     file = StringIO(str)
--> 160     return load(file)
    161 
    162 # def dumpzs(obj, protocol=None):

.../lib/python2.7/site-packages/dill/dill.pyc in load(file)
    148     pik = Unpickler(file)
    149     pik._main_module = _main_module
--> 150     obj = pik.load()
    151     if type(obj).__module__ == _main_module.__name__: # point obj class to main
    152         try: obj.__class__ == getattr(pik._main_module, type(obj).__name__)

.../lib/python2.7/pickle.pyc in load(self)
    856             while 1:
    857                 key = read(1)
--> 858                 dispatch[key](self)
    859         except _Stop, stopinst:
    860             return stopinst.value

...lib/python2.7/pickle.pyc in load_newobj(self)
   1081         args = self.stack.pop()
   1082         cls = self.stack[-1]
-> 1083         obj = cls.__new__(cls, *args)
   1084         self.stack[-1] = obj
   1085     dispatch[NEWOBJ] = load_newobj

TypeError: Required argument 'code' (pos 1) not found

I would happily prepare a PR for wrapt which enabled support for dill serialization but I’m not too sure where to start. Certainly by inspection we can see that dill has failed to serialize the wrapt function in the first place:

>> print(f_str)
'\x80\x02cdill.dill\n_load_type\nq\x00U\x0cFunctionTypeq\x01\x85q\x02Rq\x03)\x81q\x04}q\x05b.'

I don’t know if I would be better off bringing this to the dill author @mmckerns first or yourself, but if anyone can shed any light I would love to get this working.

Issue Analytics

  • State:open
  • Created 9 years ago
  • Comments:14 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
mskoenzcommented, Nov 10, 2017

Awesome package, thanks! Implementation and blog are really nice!

But the dill / serialization problem is quite nasty especially if one needs to scale a computation with multiprocessing_on_dill or concurrent.futures (e.g. to work on clusters). From a user standpoint, I fallback to decorator.decorator (which I find less nice) but allows for these large computations. For sure not a need of your typical python user, but any library that uses wrapt is not viable for these reasons.

0reactions
marwan116commented, Mar 25, 2020

@GrahamDumpleton - please refer to the following issue - (I don’t see any guidelines on issue posting so please let me know if I missed anything) - https://github.com/GrahamDumpleton/wrapt/issues/158

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to make text wrap in fillable forms - Microsoft Community
Hello, I have created a fillable form in which I would like the text to wrap and expand the tables in my form...
Read more >
Known Issues — wrapt 1.13.0rc2 documentation
This is an issue because it means that the complete descriptor binding protocol is not performed on anything which is wrapped by the...
Read more >
Wrapping Sentences in Form Fields - 3897651
When creating fillable forms, whether from a scanned document or an electronic saved copy, how can I make the form wrap sentences down...
Read more >
Helpful Hints & Tips for Navigating Screen-Fillable PDF Forms
The fillable forms available on this web site have been created using Adobe ... Acrobat Reader does not allow you to save a...
Read more >
Generate Documents - Wrap text - Smartsheet Community
I just started using the Generate Documents function, but immediately something came up ... How do I wrap text in an Adobe fillable...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found