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


Python pickle.POP属性代码示例

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


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

示例1: _save_subimports

# 需要导入模块: import pickle [as 别名]
# 或者: from pickle import POP [as 别名]
def _save_subimports(self, code, top_level_dependencies):
        """
        Ensure de-pickler imports any package child-modules that
        are needed by the function
        """
        # check if any known dependency is an imported package
        for x in top_level_dependencies:
            if isinstance(x, types.ModuleType) and hasattr(x, '__package__') and x.__package__:
                # check if the package has any currently loaded sub-imports
                prefix = x.__name__ + '.'
                for name, module in sys.modules.items():
                    # Older versions of pytest will add a "None" module to sys.modules.
                    if name is not None and name.startswith(prefix):
                        # check whether the function can address the sub-module
                        tokens = set(name[len(prefix):].split('.'))
                        if not tokens - set(code.co_names):
                            # ensure unpickler executes this import
                            self.save(module)
                            # then discards the reference to it
                            self.write(pickle.POP) 
开发者ID:FederatedAI,项目名称:FATE,代码行数:22,代码来源:cloudpickle.py

示例2: save_type

# 需要导入模块: import pickle [as 别名]
# 或者: from pickle import POP [as 别名]
def save_type(self, obj):
    if getattr(new, obj.__name__, None) is obj:
        # Types in 'new' module claim their module is '__builtin__' but are not actually there
        save_global_byname(self, obj, 'new', obj.__name__)
    elif obj.__module__ == '__main__':
        # Types in __main__ are saved by value

        # Make sure we have a reference to type.__new__        
        if id(type.__new__) not in self.memo:
            self.save_reduce(getattr, (type, '__new__'), obj=type.__new__)
            self.write(pickle.POP)

        # Copy dictproxy to real dict
        d = dict(obj.__dict__)
        # Clean up unpickleable descriptors added by Python
        d.pop('__dict__', None)
        d.pop('__weakref__', None)
        
        args = (type(obj), obj.__name__, obj.__bases__, d)
        self.save_reduce(type.__new__, args, obj=obj)
    else:
        # Fallback to default behavior: save by reference
        pickle.Pickler.save_global(self, obj) 
开发者ID:ActiveState,项目名称:code,代码行数:25,代码来源:recipe-572213.py

示例3: _save_subimports

# 需要导入模块: import pickle [as 别名]
# 或者: from pickle import POP [as 别名]
def _save_subimports(self, code, top_level_dependencies):
    """
    Ensure de-pickler imports any package child-modules that
    are needed by the function
    """
    # check if any known dependency is an imported package
    for x in top_level_dependencies:
      if isinstance(x, types.ModuleType) and hasattr(x,
                                                     '__package__') and x.__package__:
        # check if the package has any currently loaded sub-imports
        prefix = x.__name__ + '.'
        for name, module in sys.modules.items():
          # Older versions of pytest will add a "None" module to sys.modules.
          if name is not None and name.startswith(prefix):
            # check whether the function can address the sub-module
            tokens = set(name[len(prefix):].split('.'))
            if not tokens - set(code.co_names):
              # ensure unpickler executes this import
              self.save(module)
              # then discards the reference to it
              self.write(pickle.POP) 
开发者ID:WeBankFinTech,项目名称:eggroll,代码行数:23,代码来源:cloudpickle.py

示例4: _save_subimports

# 需要导入模块: import pickle [as 别名]
# 或者: from pickle import POP [as 别名]
def _save_subimports(self, code, top_level_dependencies):
        """
        Save submodules used by a function but not listed in its globals.

        In the example below:

        ```
        import concurrent.futures
        import cloudpickle


        def func():
            x = concurrent.futures.ThreadPoolExecutor


        if __name__ == '__main__':
            cloudpickle.dumps(func)
        ```

        the globals extracted by cloudpickle in the function's state include
        the concurrent module, but not its submodule (here,
        concurrent.futures), which is the module used by func.

        To ensure that calling the depickled function does not raise an
        AttributeError, this function looks for any currently loaded submodule
        that the function uses and whose parent is present in the function
        globals, and saves it before saving the function.
        """

        # check if any known dependency is an imported package
        for x in top_level_dependencies:
            if isinstance(x, types.ModuleType) and hasattr(x, '__package__') and x.__package__:
                # check if the package has any currently loaded sub-imports
                prefix = x.__name__ + '.'
                # A concurrent thread could mutate sys.modules,
                # make sure we iterate over a copy to avoid exceptions
                for name in list(sys.modules):
                    # Older versions of pytest will add a "None" module to sys.modules.
                    if name is not None and name.startswith(prefix):
                        # check whether the function can address the sub-module
                        tokens = set(name[len(prefix):].split('.'))
                        if not tokens - set(code.co_names):
                            # ensure unpickler executes this import
                            self.save(sys.modules[name])
                            # then discards the reference to it
                            self.write(pickle.POP) 
开发者ID:bentoml,项目名称:BentoML,代码行数:48,代码来源:cloudpickle.py


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