Skip to content

Commit 09d23c6

Browse files
committed
Play with random
1 parent 0ab2821 commit 09d23c6

File tree

2 files changed

+3
-7
lines changed

2 files changed

+3
-7
lines changed

enterprise_gateway/itests/test_python_kernel.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,18 +122,13 @@ def test_run_pi_example(self):
122122
pi_code = []
123123
pi_code.append("from random import random\n")
124124
pi_code.append("from operator import add\n")
125-
pi_code.append("from pyspark.cloudpickle import cloudpickle\n")
126125
pi_code.append("partitions = 20\n")
127126
pi_code.append("n = 100000 * partitions\n")
128-
# Define the function with explicit imports inside to avoid serialization issues
129127
pi_code.append("def f(_):\n")
130-
pi_code.append(" from random import random\n") # Include import inside function
128+
pi_code.append(" from random import random\n")
131129
pi_code.append(" x = random() * 2 - 1\n")
132130
pi_code.append(" y = random() * 2 - 1\n")
133131
pi_code.append(" return 1 if x ** 2 + y ** 2 <= 1 else 0\n")
134-
pi_code.append("pickled_f = cloudpickle.dumps(f)\n")
135-
pi_code.append("print('Function f successfully pickled!')\n")
136-
# Use a lambda function directly in map to avoid complex serialization
137132
pi_code.append("count = sc.parallelize(range(1, n + 1), partitions).map(f).reduce(add)\n")
138133
pi_code.append('print("Pi is roughly %f" % (4.0 * count / n))\n')
139134
result, has_error = self.kernel.execute(pi_code)

etc/kernel-launchers/python/scripts/launch_ipykernel.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
import json
66
import logging
77
import os
8-
import random
8+
99
import signal
1010
import socket
1111
import tempfile
1212
import uuid
13+
from random import random
1314
from multiprocessing import Process
1415
from threading import Thread
1516

0 commit comments

Comments
 (0)