當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。