0

My code:

def some_func():
     global values_list
     values_list.append([1,2,3,4])

if __name__ == '__main__':
     global values_list 
     values_list = []
     ...
     df.groupby(['Something',]).parallel_apply(some_func)
     print(values_list[:20])

Just an empty list is printed. I just don't understand what I am doing wrong!

LizzAlice
  • 678
  • 7
  • 18
  • Ref https://towardsdatascience.com/pandaral-lel-a-simple-and-efficient-tool-to-parallelize-your-pandas-operations-on-all-your-cpus-bb5ff2a409ae and the section "How does it work under the hood?" my guess is that your global list is not shared to the subprocesses. – Tom Dalton May 12 '20 at 13:57
  • 2
    I believe this function is meant to change/add data that is in your dataframe not that of other objects. As @TomDalton says it uses subprocesses, which means that the every subprocess will have it's own "global" values_list. For more information look here for example : https://stackoverflow.com/questions/11055303/multiprocessing-global-variable-updates-not-returned-to-parent – Marc May 12 '20 at 14:49

0 Answers0