Fixed -- Prevented shell crash on error in .pythonrc.
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)
+ 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):
