(self, func)
Pickles an actual func object.

        A func comprises: code, globals, defaults, closure, and dict.  We
        extract and save these, injecting reducing functions at certain points
        to recreate the func object.  Keep in mind that some of these pieces
        can contain a ref to the func itself.  Thus, a naive save on these
        pieces could trigger an infinite loop of save's.  To get around that,
        we first create a skeleton func object using just the code (this is
        safe, since this won't contain a ref to the func), and memoize it as
        soon as it's created.  The other stuff can then be filled in later.
Pickles an actual func object.
Pickles an actual func object .
def save_function_tuple(self, func):
        """  Pickles an actual func object.

        A func comprises: code, globals, defaults, closure, and dict.  We
        extract and save these, injecting reducing functions at certain points
        to recreate the func object.  Keep in mind that some of these pieces
        can contain a ref to the func itself.  Thus, a naive save on these
        pieces could trigger an infinite loop of save's.  To get around that,
        we first create a skeleton func object using just the code (this is
        safe, since this won't contain a ref to the func), and memoize it as
        soon as it's created.  The other stuff can then be filled in later.
        """
        if is_tornado_coroutine(func):
            self.save_reduce(_rebuild_tornado_coroutine, (func.__wrapped__,), obj=func)
            return

        save = self.save
        write = self.write

        code, f_globals, defaults, closure_values, dct, base_globals = self.extract_func_data(
            func
        )

        save(_fill_function)  # skeleton function updater
        write(pickle.MARK)  # beginning of tuple that _fill_function expects

        # Extract currently-imported submodules used by func. Storing these
        # modules in a smoke _cloudpickle_subimports attribute of the object's
        # state will trigger the side effect of importing these modules at
        # unpickling time (which is necessary for func to work correctly once
        # depickled)
        submodules = _find_imported_submodules(
            code, itertools.chain(f_globals.values(), closure_values or ())
        )

        # create a skeleton function object and memoize it
        save(_make_skel_func)
        save(
            (
                code,
                len(closure_values) if closure_values is not None else -1,
                base_globals,
            )
        )
        write(pickle.REDUCE)
        self.memoize(func)

        # save the rest of the func data needed by _fill_function
        state = {
            "globals": f_globals,
            "defaults": defaults,
            "dict": dct,
            "closure_values": closure_values,
            "module": func.__module__,
            "name": func.__name__,
            "doc": func.__doc__,
            "_cloudpickle_submodules": submodules,
        }
        if hasattr(func, "__annotations__") and sys.version_info >= (3, 7):
            # Although annotations were added in Python3.4, It is not possible
            # to properly pickle them until Python3.7. (See #193)
            state["annotations"] = func.__annotations__
        if hasattr(func, "__qualname__"):
            state["qualname"] = func.__qualname__
        if hasattr(func, "__kwdefaults__"):
            state["kwdefaults"] = func.__kwdefaults__
        save(state)
        write(pickle.TUPLE)
        write(pickle.REDUCE)
def save_function_tuple ( self , func ) : if is_tornado_coroutine ( func ) : self . save_reduce ( _rebuild_tornado_coroutine , ( func . __wrapped__ , ) , obj = func ) return save = self . save write = self . write code , f_globals , defaults , closure_values , dct , base_globals = self . extract_func_data ( func ) save ( _fill_function ) # skeleton function updater write ( pickle . MARK ) # beginning of tuple that _fill_function expects # Extract currently-imported submodules used by func. Storing these # modules in a smoke _cloudpickle_subimports attribute of the object's # state will trigger the side effect of importing these modules at # unpickling time (which is necessary for func to work correctly once # depickled) submodules = _find_imported_submodules ( code , itertools . chain ( f_globals . values ( ) , closure_values or ( ) ) ) # create a skeleton function object and memoize it save ( _make_skel_func ) save ( ( code , len ( closure_values ) if closure_values is not None else - 1 , base_globals , ) ) write ( pickle . REDUCE ) self . memoize ( func ) # save the rest of the func data needed by _fill_function state = { "globals" : f_globals , "defaults" : defaults , "dict" : dct , "closure_values" : closure_values , "module" : func . __module__ , "name" : func . __name__ , "doc" : func . __doc__ , "_cloudpickle_submodules" : submodules , } if hasattr ( func , "__annotations__" ) and sys . version_info >= ( 3 , 7 ) : # Although annotations were added in Python3.4, It is not possible # to properly pickle them until Python3.7. (See #193) state [ "annotations" ] = func . __annotations__ if hasattr ( func , "__qualname__" ) : state [ "qualname" ] = func . __qualname__ if hasattr ( func , "__kwdefaults__" ) : state [ "kwdefaults" ] = func . __kwdefaults__ save ( state ) write ( pickle . TUPLE ) write ( pickle . REDUCE )