当前位置: 首页>>代码示例>>Python>>正文


Python Pickler.dump方法代码示例

本文整理汇总了Python中pickle.Pickler.dump方法的典型用法代码示例。如果您正苦于以下问题:Python Pickler.dump方法的具体用法?Python Pickler.dump怎么用?Python Pickler.dump使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pickle.Pickler的用法示例。


在下文中一共展示了Pickler.dump方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: dumps

# 需要导入模块: from pickle import Pickler [as 别名]
# 或者: from pickle.Pickler import dump [as 别名]
def dumps(obj, protocol=None):
    """Serialize obj as a string of bytes allocated in memory

    protocol defaults to cloudpickle.DEFAULT_PROTOCOL which is an alias to
    pickle.HIGHEST_PROTOCOL. This setting favors maximum communication speed
    between processes running the same Python version.

    Set protocol=pickle.DEFAULT_PROTOCOL instead if you need to ensure
    compatibility with older versions of Python.
    """
    file = StringIO()
    try:
        cp = CloudPickler(file, protocol=protocol)
        cp.dump(obj)
        return file.getvalue()
    finally:
        file.close()


# including pickles unloading functions in this namespace 
开发者ID:pywren,项目名称:pywren-ibm-cloud,代码行数:22,代码来源:cloudpickle.py

示例2: dumps

# 需要导入模块: from pickle import Pickler [as 别名]
# 或者: from pickle.Pickler import dump [as 别名]
def dumps(obj, protocol=None):
    """Serialize obj as a string of bytes allocated in memory
    protocol defaults to cloudpickle.DEFAULT_PROTOCOL which is an alias to
    pickle.HIGHEST_PROTOCOL. This setting favors maximum communication speed
    between processes running the same Python version.
    Set protocol=pickle.DEFAULT_PROTOCOL instead if you need to ensure
    compatibility with older versions of Python.
    """
    file = StringIO()
    try:
        cp = CloudPickler(file, protocol=protocol)
        cp.dump(obj)
        return file.getvalue()
    finally:
        file.close()


# including pickles unloading functions in this namespace 
开发者ID:FederatedAI,项目名称:FATE,代码行数:20,代码来源:cloudpickle.py

示例3: dumps

# 需要导入模块: from pickle import Pickler [as 别名]
# 或者: from pickle.Pickler import dump [as 别名]
def dumps(obj, protocol=None):
  """Serialize obj as a string of bytes allocated in memory
  protocol defaults to cloudpickle.DEFAULT_PROTOCOL which is an alias to
  pickle.HIGHEST_PROTOCOL. This setting favors maximum communication speed
  between processes running the same Python version.
  Set protocol=pickle.DEFAULT_PROTOCOL instead if you need to ensure
  compatibility with older versions of Python.
  """
  file = StringIO()
  try:
    cp = CloudPickler(file, protocol=protocol)
    cp.dump(obj)
    return file.getvalue()
  finally:
    file.close()


# including pickles unloading functions in this namespace 
开发者ID:WeBankFinTech,项目名称:eggroll,代码行数:20,代码来源:cloudpickle.py

示例4: dump

# 需要导入模块: from pickle import Pickler [as 别名]
# 或者: from pickle.Pickler import dump [as 别名]
def dump(self, obj):
        self.inject_addons()
        try:
            return Pickler.dump(self, obj)
        except RuntimeError as e:
            if 'recursion' in e.args[0]:
                msg = """Could not pickle object as excessively deep recursion required."""
                raise pickle.PicklingError(msg)
            else:
                raise 
开发者ID:pywren,项目名称:pywren-ibm-cloud,代码行数:12,代码来源:cloudpickle.py

示例5: dump

# 需要导入模块: from pickle import Pickler [as 别名]
# 或者: from pickle.Pickler import dump [as 别名]
def dump(self, obj):
        self.inject_addons()
        try:
            return Pickler.dump(self, obj)
        except RuntimeError as e:
            if 'recursion' in e.args[0]:
                msg = """Could not pickle object as excessively deep recursion required."""
                raise pickle.PicklingError(msg) 
开发者ID:FederatedAI,项目名称:FATE,代码行数:10,代码来源:cloudpickle.py

示例6: dumps

# 需要导入模块: from pickle import Pickler [as 别名]
# 或者: from pickle.Pickler import dump [as 别名]
def dumps(obj, protocol=2):
    file = StringIO()
    try:
        cp = CloudPickler(file,protocol)
        cp.dump(obj)
        return file.getvalue()
    finally:
        file.close()

# including pickles unloading functions in this namespace 
开发者ID:runawayhorse001,项目名称:LearningApacheSpark,代码行数:12,代码来源:cloudpickle.py

示例7: dumps

# 需要导入模块: from pickle import Pickler [as 别名]
# 或者: from pickle.Pickler import dump [as 别名]
def dumps(obj, protocol=2):
    file = StringIO()

    cp = CloudPickler(file,protocol)
    cp.dump(obj)

    return file.getvalue()

# including pickles unloading functions in this namespace 
开发者ID:pywren,项目名称:pywren,代码行数:11,代码来源:cloudpickle.py

示例8: dump

# 需要导入模块: from pickle import Pickler [as 别名]
# 或者: from pickle.Pickler import dump [as 别名]
def dump(self, obj):
    self.inject_addons()
    try:
      return Pickler.dump(self, obj)
    except RuntimeError as e:
      if 'recursion' in e.args[0]:
        msg = """Could not pickle object as excessively deep recursion required."""
        raise pickle.PicklingError(msg) 
开发者ID:WeBankFinTech,项目名称:eggroll,代码行数:10,代码来源:cloudpickle.py

示例9: extract_func_data

# 需要导入模块: from pickle import Pickler [as 别名]
# 或者: from pickle.Pickler import dump [as 别名]
def extract_func_data(self, func):
        """
        Turn the function into a tuple of data necessary to recreate it:
            code, globals, defaults, closure_values, dict
        """
        code = func.__code__

        # extract all global ref's
        func_global_refs = _extract_code_globals(code)

        # process all variables referenced by global environment
        f_globals = {}
        for var in func_global_refs:
            if var in func.__globals__:
                f_globals[var] = func.__globals__[var]

        # defaults requires no processing
        defaults = func.__defaults__

        # process closure
        closure = (
            list(map(_get_cell_contents, func.__closure__))
            if func.__closure__ is not None
            else None
        )

        # save the dict
        dct = func.__dict__

        # base_globals represents the future global namespace of func at
        # unpickling time. Looking it up and storing it in globals_ref allow
        # functions sharing the same globals at pickling time to also
        # share them once unpickled, at one condition: since globals_ref is
        # an attribute of a Cloudpickler instance, and that a new CloudPickler is
        # created each time pickle.dump or pickle.dumps is called, functions
        # also need to be saved within the same invokation of
        # cloudpickle.dump/cloudpickle.dumps (for example: cloudpickle.dumps([f1, f2])). There
        # is no such limitation when using Cloudpickler.dump, as long as the
        # multiple invokations are bound to the same Cloudpickler.
        base_globals = self.globals_ref.setdefault(id(func.__globals__), {})

        if base_globals == {}:
            # Add module attributes used to resolve relative imports
            # instructions inside func.
            for k in ["__package__", "__name__", "__path__", "__file__"]:
                # Some built-in functions/methods such as object.__new__  have
                # their __globals__ set to None in PyPy
                if func.__globals__ is not None and k in func.__globals__:
                    base_globals[k] = func.__globals__[k]

        return (code, f_globals, defaults, closure, dct, base_globals) 
开发者ID:pywren,项目名称:pywren-ibm-cloud,代码行数:53,代码来源:cloudpickle.py

示例10: extract_func_data

# 需要导入模块: from pickle import Pickler [as 别名]
# 或者: from pickle.Pickler import dump [as 别名]
def extract_func_data(self, func):
        """
        Turn the function into a tuple of data necessary to recreate it:
            code, globals, defaults, closure_values, dict
        """
        code = func.__code__

        # extract all global ref's
        func_global_refs = self.extract_code_globals(code)

        # process all variables referenced by global environment
        f_globals = {}
        for var in func_global_refs:
            if var in func.__globals__:
                f_globals[var] = func.__globals__[var]

        # defaults requires no processing
        defaults = func.__defaults__

        # process closure
        closure = (
            list(map(_get_cell_contents, func.__closure__))
            if func.__closure__ is not None
            else None
        )

        # save the dict
        dct = func.__dict__

        # base_globals represents the future global namespace of func at
        # unpickling time. Looking it up and storing it in globals_ref allow
        # functions sharing the same globals at pickling time to also
        # share them once unpickled, at one condition: since globals_ref is
        # an attribute of a Cloudpickler instance, and that a new CloudPickler is
        # created each time pickle.dump or pickle.dumps is called, functions
        # also need to be saved within the same invokation of
        # cloudpickle.dump/cloudpickle.dumps (for example: cloudpickle.dumps([f1, f2])). There
        # is no such limitation when using Cloudpickler.dump, as long as the
        # multiple invokations are bound to the same Cloudpickler.
        base_globals = self.globals_ref.setdefault(id(func.__globals__), {})

        if base_globals == {}:
            # Add module attributes used to resolve relative imports
            # instructions inside func.
            for k in ["__package__", "__name__", "__path__", "__file__"]:
                # Some built-in functions/methods such as object.__new__  have
                # their __globals__ set to None in PyPy
                if func.__globals__ is not None and k in func.__globals__:
                    base_globals[k] = func.__globals__[k]

        return (code, f_globals, defaults, closure, dct, base_globals) 
开发者ID:bentoml,项目名称:BentoML,代码行数:53,代码来源:cloudpickle.py


注:本文中的pickle.Pickler.dump方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。