带有 ipython 的 dill dump_session

2024-02-20

我正在尝试使用 dill 模块来保存我的 ipython 会话dump_session()但我收到一条错误消息。我正在使用 Ipython 1.0.0 和 dill 0.2-a-dev 20120503。有人有任何见解吗?提前致谢。

Niall

这是巨大的回溯:

--------------------------------------------------------------------------- AssertionError                            Traceback (most recent call last) <ipython-input-15-9934c16a537e> in <module>()
----> 1 dill.dump_session("/data/local/nrobin/tset.sess")

/home/h02/nrobin/.local/lib/python2.7/site-packages/dill-0.2a.dev_20120503-py2.7.egg/dill/dill.pyc in dump_session(filename, main_module)
    104         pickler._main_module = main_module
    105         pickler._session = True # is best indicator of when pickling a session
--> 106         pickler.dump(main_module)
    107         pickler._session = False
    108     finally:

/usr/local/sci/lib/python2.7/pickle.pyc in dump(self, obj)
    222         if self.proto >= 2:
    223             self.write(PROTO + chr(self.proto))
--> 224         self.save(obj)
    225         self.write(STOP)
    226 

/usr/local/sci/lib/python2.7/pickle.pyc in save(self, obj)
    284         f = self.dispatch.get(t)
    285         if f:
--> 286             f(self, obj) # Call unbound method with explicit self
    287             return
    288 

/home/h02/nrobin/.local/lib/python2.7/site-packages/dill-0.2a.dev_20120503-py2.7.egg/dill/dill.pyc in save_module(pickler, obj)
    415         if _DEBUG[0]: print "M1: %s" % obj
    416         pickler.save_reduce(__import__, (obj.__name__,), obj=obj,
--> 417                             state=obj.__dict__.copy())
    418     else:
    419         if _DEBUG[0]: print "M2: %s" % obj

/usr/local/sci/lib/python2.7/pickle.pyc in save_reduce(self, func, args, state, listitems, dictitems, obj)
    417 
    418         if state is not None:
--> 419             save(state)
    420             write(BUILD)
    421 

/usr/local/sci/lib/python2.7/pickle.pyc in save(self, obj)
    284         f = self.dispatch.get(t)
    285         if f:
--> 286             f(self, obj) # Call unbound method with explicit self
    287             return
    288 

/home/h02/nrobin/.local/lib/python2.7/site-packages/dill-0.2a.dev_20120503-py2.7.egg/dill/dill.pyc in save_module_dict(pickler, obj)
    284     else:
    285         if _DEBUG[0]: print "D2: %s" % "<dict ...>" #obj
--> 286         StockPickler.save_dict(pickler, obj)
    287     return
    288 

/usr/local/sci/lib/python2.7/pickle.pyc in save_dict(self, obj)
    647 
    648         self.memoize(obj)
--> 649         self._batch_setitems(obj.iteritems())
    650 
    651     dispatch[DictionaryType] = save_dict

/usr/local/sci/lib/python2.7/pickle.pyc in _batch_setitems(self, items)
    679                 for k, v in tmp:
    680                     save(k)
--> 681                     save(v)
    682                 write(SETITEMS)
    683             elif n:

/usr/local/sci/lib/python2.7/pickle.pyc in save(self, obj)
    329 
    330         # Save the reduce() output and finally memoize the object
--> 331         self.save_reduce(obj=obj, *rv)
    332 
    333     def persistent_id(self, obj):

/usr/local/sci/lib/python2.7/pickle.pyc in save_reduce(self, func, args, state, listitems, dictitems, obj)
    417 
    418         if state is not None:
--> 419             save(state)
    420             write(BUILD)
    421 

/usr/local/sci/lib/python2.7/pickle.pyc in save(self, obj)
    284         f = self.dispatch.get(t)
    285         if f:
--> 286             f(self, obj) # Call unbound method with explicit self
    287             return
    288 

/home/h02/nrobin/.local/lib/python2.7/site-packages/dill-0.2a.dev_20120503-py2.7.egg/dill/dill.pyc in save_module_dict(pickler, obj)
    284     else:
    285         if _DEBUG[0]: print "D2: %s" % "<dict ...>" #obj
--> 286         StockPickler.save_dict(pickler, obj)
    287     return
    288 

/usr/local/sci/lib/python2.7/pickle.pyc in save_dict(self, obj)
    647 
    648         self.memoize(obj)
--> 649         self._batch_setitems(obj.iteritems())
    650 
    651     dispatch[DictionaryType] = save_dict

/usr/local/sci/lib/python2.7/pickle.pyc in _batch_setitems(self, items)
    684                 k, v = tmp[0]
    685                 save(k)
--> 686                 save(v)
    687                 write(SETITEM)
    688             # else tmp is empty, and we're done

/usr/local/sci/lib/python2.7/pickle.pyc in save(self, obj)
    329 
    330         # Save the reduce() output and finally memoize the object
--> 331         self.save_reduce(obj=obj, *rv)
    332 
    333     def persistent_id(self, obj):

/usr/local/sci/lib/python2.7/pickle.pyc in save_reduce(self, func, args, state, listitems, dictitems, obj)
    417 
    418         if state is not None:
--> 419             save(state)
    420             write(BUILD)
    421 

/usr/local/sci/lib/python2.7/pickle.pyc in save(self, obj)
    284         f = self.dispatch.get(t)
    285         if f:
--> 286             f(self, obj) # Call unbound method with explicit self
    287             return
    288 

/home/h02/nrobin/.local/lib/python2.7/site-packages/dill-0.2a.dev_20120503-py2.7.egg/dill/dill.pyc in save_module_dict(pickler, obj)
    284     else:
    285         if _DEBUG[0]: print "D2: %s" % "<dict ...>" #obj
--> 286         StockPickler.save_dict(pickler, obj)
    287     return
    288 

/usr/local/sci/lib/python2.7/pickle.pyc in save_dict(self, obj)
    647 
    648         self.memoize(obj)
--> 649         self._batch_setitems(obj.iteritems())
    650 
    651     dispatch[DictionaryType] = save_dict

/usr/local/sci/lib/python2.7/pickle.pyc in _batch_setitems(self, items)
    679                 for k, v in tmp:
    680                     save(k)
--> 681                     save(v)
    682                 write(SETITEMS)
    683             elif n:

/usr/local/sci/lib/python2.7/pickle.pyc in save(self, obj)
    284         f = self.dispatch.get(t)
    285         if f:
--> 286             f(self, obj) # Call unbound method with explicit self
    287             return
    288 

/home/h02/nrobin/.local/lib/python2.7/site-packages/dill-0.2a.dev_20120503-py2.7.egg/dill/dill.pyc in save_instancemethod(pickler, obj)
    303     if _DEBUG[0]: print "Me: %s" % obj
    304     pickler.save_reduce(MethodType, (obj.im_func, obj.im_self,
--> 305                                      obj.im_class), obj=obj)
    306     return
    307 

/usr/local/sci/lib/python2.7/pickle.pyc in save_reduce(self, func, args, state, listitems, dictitems, obj)
    399         else:
    400             save(func)
--> 401             save(args)
    402             write(REDUCE)
    403 

/usr/local/sci/lib/python2.7/pickle.pyc in save(self, obj)
    284         f = self.dispatch.get(t)
    285         if f:
--> 286             f(self, obj) # Call unbound method with explicit self
    287             return
    288 

/usr/local/sci/lib/python2.7/pickle.pyc in save_tuple(self, obj)
    546         if n <= 3 and proto >= 2:
    547             for element in obj:
--> 548                 save(element)
    549             # Subtle.  Same as in the big comment below.
    550             if id(obj) in memo:

/usr/local/sci/lib/python2.7/pickle.pyc in save(self, obj)
    284         f = self.dispatch.get(t)
    285         if f:
--> 286             f(self, obj) # Call unbound method with explicit self
    287             return
    288 

/home/h02/nrobin/.local/lib/python2.7/site-packages/dill-0.2a.dev_20120503-py2.7.egg/dill/dill.pyc in save_function(pickler, obj)
    268         pickler.save_reduce(FunctionType, (obj.func_code, obj.func_globals,
    269                                            obj.func_name, obj.func_defaults,
--> 270                                            obj.func_closure), obj=obj)
    271     else:
    272         if _DEBUG[0]: print "F2: %s" % obj

/usr/local/sci/lib/python2.7/pickle.pyc in save_reduce(self, func, args, state, listitems, dictitems, obj)
    399         else:
    400             save(func)
--> 401             save(args)
    402             write(REDUCE)
    403 

/usr/local/sci/lib/python2.7/pickle.pyc in save(self, obj)
    284         f = self.dispatch.get(t)
    285         if f:
--> 286             f(self, obj) # Call unbound method with explicit self
    287             return
    288 

/usr/local/sci/lib/python2.7/pickle.pyc in save_tuple(self, obj)
    560         write(MARK)
    561         for element in obj:
--> 562             save(element)
    563 
    564         if id(obj) in memo:

/usr/local/sci/lib/python2.7/pickle.pyc in save(self, obj)
    284         f = self.dispatch.get(t)
    285         if f:
--> 286             f(self, obj) # Call unbound method with explicit self
    287             return
    288 

/home/h02/nrobin/.local/lib/python2.7/site-packages/dill-0.2a.dev_20120503-py2.7.egg/dill/dill.pyc in save_module_dict(pickler, obj)
    284     else:
    285         if _DEBUG[0]: print "D2: %s" % "<dict ...>" #obj
--> 286         StockPickler.save_dict(pickler, obj)
    287     return
    288 

/usr/local/sci/lib/python2.7/pickle.pyc in save_dict(self, obj)
    647 
    648         self.memoize(obj)
--> 649         self._batch_setitems(obj.iteritems())
    650 
    651     dispatch[DictionaryType] = save_dict

/usr/local/sci/lib/python2.7/pickle.pyc in _batch_setitems(self, items)
    679                 for k, v in tmp:
    680                     save(k)
--> 681                     save(v)
    682                 write(SETITEMS)
    683             elif n:

/usr/local/sci/lib/python2.7/pickle.pyc in save(self, obj)
    284         f = self.dispatch.get(t)
    285         if f:
--> 286             f(self, obj) # Call unbound method with explicit self
    287             return
    288 

/home/h02/nrobin/.local/lib/python2.7/site-packages/dill-0.2a.dev_20120503-py2.7.egg/dill/dill.pyc in save_instancemethod(pickler, obj)
    303     if _DEBUG[0]: print "Me: %s" % obj
    304     pickler.save_reduce(MethodType, (obj.im_func, obj.im_self,
--> 305                                      obj.im_class), obj=obj)
    306     return
    307 

/usr/local/sci/lib/python2.7/pickle.pyc in save_reduce(self, func, args, state, listitems, dictitems, obj)
    399         else:
    400             save(func)
--> 401             save(args)
    402             write(REDUCE)
    403 

/usr/local/sci/lib/python2.7/pickle.pyc in save(self, obj)
    284         f = self.dispatch.get(t)
    285         if f:
--> 286             f(self, obj) # Call unbound method with explicit self
    287             return
    288 

/usr/local/sci/lib/python2.7/pickle.pyc in save_tuple(self, obj)
    546         if n <= 3 and proto >= 2:
    547             for element in obj:
--> 548                 save(element)
    549             # Subtle.  Same as in the big comment below.
    550             if id(obj) in memo:

/usr/local/sci/lib/python2.7/pickle.pyc in save(self, obj)
    284         f = self.dispatch.get(t)
    285         if f:
--> 286             f(self, obj) # Call unbound method with explicit self
    287             return
    288 

/home/h02/nrobin/.local/lib/python2.7/site-packages/dill-0.2a.dev_20120503-py2.7.egg/dill/dill.pyc in save_function(pickler, obj)
    268         pickler.save_reduce(FunctionType, (obj.func_code, obj.func_globals,
    269                                            obj.func_name, obj.func_defaults,
--> 270                                            obj.func_closure), obj=obj)
    271     else:
    272         if _DEBUG[0]: print "F2: %s" % obj

/usr/local/sci/lib/python2.7/pickle.pyc in save_reduce(self, func, args, state, listitems, dictitems, obj)
    403 
    404         if obj is not None:
--> 405             self.memoize(obj)
    406 
    407         # More new special cases (that work with older protocols as

/usr/local/sci/lib/python2.7/pickle.pyc in memoize(self, obj)
    242         if self.fast:
    243             return
--> 244         assert id(obj) not in self.memo
    245         memo_len = len(self.memo)
    246         self.write(self.put(memo_len))

AssertionError:

由于 ipython 的“退出”类型,dill.dump_session 在 ipython 中不起作用...基本上,ipython 劫持了解释器的退出方法并将其转换为某种新的对象类型。我有一个标志可以识别何时“IPYTHON 为 True”...但是 dump_session 仍然在全局变量中看到 ipython 的退出类型,这些类型保存在会话转储中。现在,我假设他们是单身......并且不拯救他们。看起来它从 dill 修订版 #511 开始工作,您可以将 ipython 会话序列化到文件中。

如果您在 ipython 中发现其他问题,请告诉我,因为我依赖 ipython 用户在 ipython 中的 dill 出现问题时告诉我。

更新已发布到 github,地址为https://github.com/uqfoundation https://github.com/uqfoundation, 以及问题跟踪器http://trac.mystic.cacr.caltech.edu/project/pathos/ticket/131 http://trac.mystic.cacr.caltech.edu/project/pathos/ticket/131.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

带有 ipython 的 dill dump_session 的相关文章

  • IPython 的历史向后搜索未按预期工作

    IPython 的history search backward功能是我最喜欢的功能之一 history search backward允许您键入命令的一部分 然后在阅读行历史记录中向后搜索以该命令的该部分开头的命令 默认情况下 我相信 这
  • 如何在 Jupyter 中插入文字选项卡而不是自动完成?

    缩进整行很容易 Just highlight the whole line and press Tab Go to the start of the line and press Tab Click anywhere in the line
  • Python 中 pickle 的常见用例

    我看过pickle http en wikipedia org wiki Pickle 28Python 29文档 但我不明白 pickle 在哪里有用 pickle 的一些常见用例有哪些 我遇到过的一些用途 1 将程序的状态数据保存到磁盘
  • IPython 中带多个参数的并行映射函数

    我正在尝试使用 IPython 的并行环境 到目前为止 它看起来很棒 但我遇到了问题 假设我有一个在库中定义的函数 def func a b 当我想要评估 a 的一个值和 b 的一组值时 我会使用它 func myA b for b in
  • Spyder3 - AttributeError:“SpyderKernel”对象没有属性“_show_mpl_backend_errors”

    我的 Spyder3 有问题 当我打开它时 控制台上会出现此警告 Python 3 8 5 default Jul 28 2020 12 59 40 Type copyright credits or license for more in
  • %matplotlib inline 在 jupyter 笔记本上不显示任何绘图

    matplotlib pyplot运行时间很长 最后屏幕上没有显示任何情节 But matplotlib back end 给出以下 u TkAgg 有人可以提出解决方案吗 注意 我使用安装了 matplotlibpip install m
  • 如何在 Python 中从文件中 unpickle 一系列对象?

    我已以追加模式将对象腌制到文件中 但它只读取单个对象 这是代码 我不知道我做错了什么 with open notes pkl ab as fileObject append pickle dump obj fileObject pickle
  • 如何在 Jupyter 中使用 JavaScript 选择当前单元格?

    我有一个包含 JavaScript 代码的笔记本单元格 我希望代码能够选择这个特定的单元格 不幸的是 get selected cell取决于我是就地执行单元格 还是执行并选择下面的单元格 Example javascript var ce
  • 您可以指定嵌入 IPython 后运行的命令吗?

    打电话时IPython embed 是否可以给它一个命令或魔术函数来在嵌入发生后运行 我想运行这样的东西 import IPython IPython embed command pylab qt4 我当前的解决方法是将命令字符串复制到剪贴
  • Python:检查对象是否可以原子方式pickle

    检查对象是否可以被原子腌制的准确方法是什么 当我说 原子腌制 时 我的意思是不考虑它可能引用的其他对象 例如 这个列表 l threading Lock 不是一个可腌制的对象 因为它指的是Lock这是不可腌制的 但从原子角度来看 这个列表本
  • copy.deepcopy 与 pickle

    我有一个小部件的树结构 例如集合包含模型 模型包含小部件 我想复制整个收藏 copy deepcopy与 pickle and de pickle 对象相比更快 但用 C 编写的 cPickle 更快 因此 为什么我 我们 不应该总是使用
  • Python - 将多个 Pickle 对象加载到单个字典中

    所以我的问题是这样的 我有多个 Pickle 对象文件 即 Pickled 字典 我想加载它们 但本质上是将每个字典合并到一个更大的字典中 E g 我有 pickle file1 和 pickle file2 都包含字典 我希望将 pick
  • 如何更新 IPython 5.0 的 PromptManager 设置?

    线条 Output prompt will be transformed to the prompt number c PromptManager out template color Green Out count color Green
  • 使用python sklearn增量训练随机森林模型

    我使用下面的代码来保存随机森林模型 我正在使用 cPickle 保存训练后的模型 当我看到新数据时 我可以增量训练模型吗 目前 训练集大约有2年的数据 有没有办法再训练两年并将其 某种程度上 附加到现有保存的模型中 rf RandomFor
  • 通过 IPython 使用 Jython:readline 仍然是一个问题吗?

    我想将 Jython 解释器与 IPython 一起使用 这样我就可以使用制表符补全之类的东西 也许还可以使用 IPython 笔记本 这IPython 常见问题解答网站 http ipython org faq html围绕这是否可行采取
  • 未找到神奇函数“bash”

    我有一堆模拟想要在高性能集群上运行 我应该在这些集群上进行预留以获得计算时间 由于预订是有时间限制的 我正在开发一个自动化脚本 我可以scp进入集群并运行 然后 该脚本将下载相关的模拟文件 运行它们 并上传结果 该自动化脚本的一部分位于ba
  • 如何在 python 中 unpickle 托管在 Web URL 中的文件

    pickle 和 unpickle 对象的正常方法如下 腌制一个对象 import cloudpickle as cp cp dump objects open picklefile pkl wb UnPickle 一个对象 加载腌制文件
  • 如何处理 Ipython Notebook 中的引用?

    在 Ipython Notebook 中处理引用的最佳方法是什么 理想情况下 我想要一个 bibtex 文件 然后像在 Latex 中一样 在 Ipython markdown 单元格中拥有一个速记列表 并在笔记本末尾提供完整的参考文献 我
  • iPython 笔记本上的内联数学模式

    在 iPython 笔记本中 我如何编写数学公式 例如r 2在一行中 乳胶词汇中的内联数学模式 IE 打印公式的时候可以不换行吗 如果像在 LaTeX 中一样 它应该是 r 2 但它不起作用 感谢您的帮助 在 Markdown 单元格中 您
  • 更改 IPython 笔记本小部件中标签的大小

    这确实是一个小问题 但仍然很烦人 我正在编写一个工具 允许用户设置一堆数字参数以在 IPython 笔记本中进行分析 我把它设置为一堆FloatTextWidgets in a ContainerWidget 它们有相当长的标签 例如 姿势

随机推荐