0

I have been using dill ever since this question of mine got answered very well by the package maintainer.

Recently however, in my use case, I am getting the following error:

stored_env = dill.load(f_in)
  File "A:\anaconda\lib\site-packages\dill\dill.py", line 250, in load
    obj = pik.load()
  File "A:\anaconda\lib\pickle.py", line 864, in load
    dispatch[key](self)
KeyError: '\x7f'

What might this mean?

I am using dill version: '0.2.5', as retrieved by pip install dill

I tried setting dill.detect.trace(True), but I get no output from that.

EDIT: Here's a minimal example that does not work:

#test.py
import numba as nb
import numpy as np

@nb.jit(nopython=True)
def my_fast_vector_add(x, y):
    num_elements = x.shape[0]
    z = np.zeros(num_elements, dtype=np.float64)

    for i in range(num_elements):
        z[i] = x[i] + y[i]

    return z  

class Environment():
    def __init__(self):
        self.x = np.random.rand(10)
        self.y = np.random.rand(10)

    def my_vector_add(self):
        return my_fast_vector_add(self.x, self.y)

And the code that puts it all together:

#doit.py
import test
import dill
import os
import shutil
import gzip

env = test.Environment()
print "init add result: ", env.my_vector_add()
pkl_path = "test.pkl"

with open(pkl_path, 'w') as f:
    dill.dump(env, f)

compressed_path = "test.zip"

with open(pkl_path, 'r') as f_in, gzip.open(compressed_path, 'wb') as f_out:
    shutil.copyfileobj(f_in, f_out)

os.remove(pkl_path)

stored_env = None
with gzip.open(compressed_path, 'r') as f_in:
    stored_env = dill.load(f_in)
    print "loaded add result: ", stored_env.my_vector_add()

The error that is produced is:

    exec(compile(scripttext, filename, 'exec'), glob, loc)
  File "A:/dill_issue/doit.py", line 25, in <module>
    stored_env = dill.load(f_in)
  File "A:\anaconda\lib\site-packages\dill\dill.py", line 250, in load
    obj = pik.load()
  File "A:\anaconda\lib\pickle.py", line 864, in load
    dispatch[key](self)
  File "A:\anaconda\lib\pickle.py", line 886, in load_eof
    raise EOFError
EOFError
Community
  • 1
  • 1
bzm3r
  • 3,113
  • 6
  • 34
  • 67
  • similar to your Q? http://stackoverflow.com/a/26350991/4646678 – Mike McKerns Feb 15 '16 at 18:57
  • Might be some encoding issue, similar to http://stackoverflow.com/a/11314602/4646678. If so, I think `dill` is missing an `encoding` keyword. – Mike McKerns Feb 15 '16 at 19:03
  • @MikeMcKerns re: http://stackoverflow.com/a/26350991/4646678, it looks similar at first glance, but luckily I am making sure to unzip the file with gzip (`gzip.open`) instead of just using normal file open to read it? – bzm3r Feb 15 '16 at 19:38
  • @MikeMcKerns re: http://stackoverflow.com/a/11314602/4646678, not totally sure how that issue relates back to my problem, as I don't think I really understand what's going on here -- I am using Python 2.7 though – bzm3r Feb 15 '16 at 19:42
  • @MikeMcKerns I finally got a minimal example that produces an error close to what I am getting in my main body of code! In particular, what is needed is a reference to a numba decorated function `my_fast_vector_add` inside the class `test.Environment` – bzm3r Feb 15 '16 at 21:33
  • @MikeMcKerns Also, if you replace `dill` with `pickle` in the minimal example, everything works okay – bzm3r Feb 15 '16 at 21:34
  • @MikeMcKerns in particular, if the problem is with `dill.dump` (because if `pickle.dump` is used, then both `dill.load` and `pickle.load` are fine) – bzm3r Feb 15 '16 at 21:40
  • Your example works for me… both when I run from `doit.py` and also if instead I run from the interpreter. I am using the latest version of `dill` (0.2.6.dev0 from github), `numpy` version 1.10.2, `numba` version 0.22.1, and python version 2..7.11 on a MacOSX. Can you either give more versioning detail here, or fill out a ticket on the `dill` github page? – Mike McKerns Feb 15 '16 at 22:12
  • @MikeMcKerns I moved away from the problem for a bit, to work on some other issues, but now I am back here again. I don't get this error anymore, when using `dill` (0.2.6.dev0), but I am still having trouble...I think it's a different issue (even though it seems similar), so I'll write it up as a github issue – bzm3r Feb 21 '16 at 19:37
  • @MikeMcKerns posted a ticket here: https://github.com/uqfoundation/dill/issues/158 – bzm3r Feb 21 '16 at 20:30

1 Answers1

1

Apparently the answer is to upgrade from dill-0.2.5 to dill-0.2.6.dev0.

Mike McKerns
  • 33,715
  • 8
  • 119
  • 139
  • I accepted your answer, but I am not totally sure if the new error I am getting is unrelated...it still has `dispatch[key]` bit...but just reads a little differently? See: https://github.com/uqfoundation/dill/issues/158 – bzm3r Feb 24 '16 at 20:11
  • Thanks. I'll look at the issue and address it directly. – Mike McKerns Feb 24 '16 at 22:53