File tree Expand file tree Collapse file tree 1 file changed +3
-0
lines changed 
enterprise_gateway/itests Expand file tree Collapse file tree 1 file changed +3
-0
lines changed Original file line number Diff line number Diff line change @@ -124,10 +124,13 @@ def test_run_pi_example(self):
124124        pi_code .append ("from operator import add\n " )
125125        pi_code .append ("partitions = 20\n " )
126126        pi_code .append ("n = 100000 * partitions\n " )
127+         # Define the function with explicit imports inside to avoid serialization issues 
127128        pi_code .append ("def f(_):\n " )
129+         pi_code .append ("    from random import random\n " )  # Include import inside function 
128130        pi_code .append ("    x = random() * 2 - 1\n " )
129131        pi_code .append ("    y = random() * 2 - 1\n " )
130132        pi_code .append ("    return 1 if x ** 2 + y ** 2 <= 1 else 0\n " )
133+         # Use a lambda function directly in map to avoid complex serialization 
131134        pi_code .append ("count = sc.parallelize(range(1, n + 1), partitions).map(f).reduce(add)\n " )
132135        pi_code .append ('print("Pi is roughly %f" % (4.0 * count / n))\n ' )
133136        result , has_error  =  self .kernel .execute (pi_code )
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments