Created
          March 15, 2019 05:11 
        
      - 
      
- 
        Save naranjja/72373ecdc4ba911d39c4dbd9b95b2d82 to your computer and use it in GitHub Desktop. 
    Simple parallelizing of for loop in Python
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import multiprocessing, joblib | |
| def parallelize(iter_expression, func): | |
| func = func.replace("(", ")(") | |
| n_jobs = multiprocessing.cpu_count() | |
| return eval("joblib.Parallel(n_jobs={})(joblib.delayed({} {})".format(n_jobs, func, iter_expression)) | |
| parallelize("for i in range(10)", "print(i)") | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment