Fixed #27670 -- Prevented shell crash on error in .pythonrc.
This commit is contained in:
parent
cf57ecb221
commit
0ba57c3957
|
@ -1,6 +1,7 @@
|
|||
import os
|
||||
import select
|
||||
import sys
|
||||
import traceback
|
||||
from contextlib import suppress
|
||||
|
||||
from django.core.management import BaseCommand, CommandError
|
||||
|
@ -69,9 +70,15 @@ class Command(BaseCommand):
|
|||
continue
|
||||
if not os.path.isfile(pythonrc):
|
||||
continue
|
||||
with suppress(NameError):
|
||||
with open(pythonrc) as handle:
|
||||
exec(compile(handle.read(), pythonrc, 'exec'), imported_objects)
|
||||
with open(pythonrc) as handle:
|
||||
pythonrc_code = handle.read()
|
||||
# Match the behavior of the cpython shell where an error in
|
||||
# PYTHONSTARTUP prints an exception and continues.
|
||||
try:
|
||||
exec(compile(pythonrc_code, pythonrc, 'exec'), imported_objects)
|
||||
except Exception:
|
||||
traceback.print_exc()
|
||||
|
||||
code.interact(local=imported_objects)
|
||||
|
||||
def handle(self, **options):
|
||||
|
|
Loading…
Reference in New Issue