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

    https://github.com/apache/spark/pull/2522#discussion_r17994793
  
    --- 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 --
    
    Based on a read through this PR, it looks like this line is the first place 
where this function diverges from the pre-#2144 version of `cloudpickle`.
    
    It looks like the original version of `cloudpickle` called this code from 
outside of  `extract_code_globals`, so I guess the old code would only perform 
one level of recursion when trying to extract globals?
    
    Do you think that adding actual, unbounded recursion could cause problems 
here?  If the "nested function" implies that this only applies to functions 
defined within other functions, then there aren't cycles in the nesting and 
therefore shouldn't be cycles that lead to infinite recursion.


---
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