Skip to content

Commit

Permalink
Fixed #29774 -- Fixed django-admin shell hang on startup.
Browse files Browse the repository at this point in the history
sys.stdin.read() blocks waiting for EOF in shell.py which will
likely never come if the user provides input on stdin via the
keyboard before the shell starts. Added check for a tty to
skip reading stdin if it's not present.

This still allows piping of code into the shell (which should
have no TTY and should have an EOF) but also doesn't cause it
to hang if multi-line input is provided.
  • Loading branch information
Adam Allred authored and timgraham committed Oct 20, 2018
1 parent a29fce8 commit 4e78e38
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ answer newbie questions, and generally made Django that much better:
Abeer Upadhyay <[email protected]>
Abhinav Patil <https://github.com/ubadub/>
Abhishek Gautam <[email protected]>
Adam Allred <[email protected]>
Adam Bogdał <[email protected]>
Adam Donaghy
Adam Johnson <https://github.com/adamchainz>
Expand Down
2 changes: 1 addition & 1 deletion django/core/management/commands/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def handle(self, **options):

# Execute stdin if it has anything to read and exit.
# Not supported on Windows due to select.select() limitations.
if sys.platform != 'win32' and select.select([sys.stdin], [], [], 0)[0]:
if sys.platform != 'win32' and not sys.stdin.isatty() and select.select([sys.stdin], [], [], 0)[0]:
exec(sys.stdin.read())
return

Expand Down
3 changes: 3 additions & 0 deletions docs/releases/2.1.3.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ Bugfixes

* Fixed a regression in Django 2.0 where combining ``Q`` objects with ``__in``
lookups and lists crashed (:ticket:`29838`).

* Fixed a regression in Django 1.11 where ``django-admin shell`` may hang
on startup (:ticket:`29774`).

0 comments on commit 4e78e38

Please sign in to comment.