code: def find_all_globals(node, globs):
      
      for n in node:
          if isinstance(n, SyntaxTree):
              globs = find_all_globals(n, globs)
          elif n.kind in read_write_global_ops:
              globs.add(n.pattr)
      return globs
docs: Search Syntax Tree node to find variable names that are global.