Skip to content

Commit cf6d506

Browse files
erikselinJoshRosen
authored andcommitted
[SPARK-12268][PYSPARK] Make pyspark shell pythonstartup work under python3
This replaces the `execfile` used for running custom python shell scripts with explicit open, compile and exec (as recommended by 2to3). The reason for this change is to make the pythonstartup option compatible with python3. Author: Erik Selin <erik.selin@gmail.com> Closes #10255 from tyro89/pythonstartup-python3. (cherry picked from commit e4e0b3f) Signed-off-by: Josh Rosen <joshrosen@databricks.com>
1 parent 364f799 commit cf6d506

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

python/pyspark/shell.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,6 @@
7676
# which allows us to execute the user's PYTHONSTARTUP file:
7777
_pythonstartup = os.environ.get('OLD_PYTHONSTARTUP')
7878
if _pythonstartup and os.path.isfile(_pythonstartup):
79-
execfile(_pythonstartup)
79+
with open(_pythonstartup) as f:
80+
code = compile(f.read(), _pythonstartup, 'exec')
81+
exec(code)

0 commit comments

Comments
 (0)