Github user davies commented on a diff in the pull request:

    https://github.com/apache/spark/pull/2522#discussion_r17995491
  
    --- Diff: python/pyspark/cloudpickle.py ---
    @@ -304,16 +313,37 @@ def save_function_tuple(self, func, forced_imports):
             write(pickle.REDUCE)  # applies _fill_function on the tuple
     
         @staticmethod
    -    def extract_code_globals(code):
    +    def extract_code_globals(co):
             """
             Find all globals names read or written to by codeblock co
             """
    -        names = set(code.co_names)
    -        if code.co_consts:   # see if nested function have any global refs
    -            for const in code.co_consts:
    +        code = co.co_code
    +        names = co.co_names
    +        out_names = set()
    +
    +        n = len(code)
    +        i = 0
    +        extended_arg = 0
    +        while i < n:
    +            op = code[i]
    +
    +            i = i+1
    +            if op >= HAVE_ARGUMENT:
    +                oparg = ord(code[i]) + ord(code[i+1])*256 + extended_arg
    +                extended_arg = 0
    +                i = i+2
    +                if op == EXTENDED_ARG:
    +                    extended_arg = oparg*65536L
    +                if op in GLOBAL_OPS:
    +                    out_names.add(names[oparg])
    +        #print 'extracted', out_names, ' from ', names
    +
    +        if co.co_consts:   # see if nested function have any global refs
    --- End diff --
    
    The original code only perform two levels of functions, the new version can 
handle multiple levels.
    
    Each level is on function code, which is created by `def` or `lambda`, so I 
think the code cannot be recursive.
    
     


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to