#29774 closed Bug (fixed)
`django-admin shell` hangs if the user hit enter before shell is ready
| Reported by: | Craig de Stigter | Owned by: | Adam Allred | 
|---|---|---|---|
| Component: | Core (Management commands) | Version: | dev | 
| Severity: | Normal | Keywords: | hang, shell | 
| Cc: | Triage Stage: | Accepted | |
| Has patch: | yes | Needs documentation: | no | 
| Needs tests: | no | Patch needs improvement: | no | 
| Easy pickings: | no | UI/UX: | no | 
Description (last modified by )
We have a large project with a fairly slow startup time:
$ time bash -c "echo 'pass' | django-admin shell" real 0m5.596s user 0m1.080s sys 0m1.548s
As a habit, I tend to run django-admin shell, and while it's loading, begin to type my first command.
Since upgrading from django 1.8 to 1.11, this causes the whole process to hang with no output. After about 30s I notice and ctrl+C, but it's incredibly frustrating:
$ django-admin shell
typing while i wait...
^CTraceback (most recent call last):
  File "/kx/dandelion/venv/bin/django-admin", line 11, in <module>
    sys.exit(execute_from_command_line())
  File "/kx/dandelion/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
    utility.execute()
  File "/kx/dandelion/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 356, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/kx/dandelion/venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 283, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/kx/dandelion/venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 330, in execute
    output = self.handle(*args, **options)
  File "/kx/dandelion/venv/local/lib/python2.7/site-packages/django/core/management/commands/shell.py", line 101, in handle
    exec(sys.stdin.read())
KeyboardInterrupt
Multiple people on our team have experienced this.
It seems to happen if I manage to type at least one line before it loads. If I just type a few characters not including a newline, the hang doesn't occur.
I traced the issue to this addition in the django 1.11 release. It is still present in master.
Change History (7)
comment:1 by , 7 years ago
| Description: | modified (diff) | 
|---|
comment:2 by , 7 years ago
| Summary: | `django-admin shell` hangs if the user starts typing before shell is ready → `django-admin shell` hangs if the user hit enter before shell is ready | 
|---|---|
| Triage Stage: | Unreviewed → Accepted | 
comment:3 by , 7 years ago
| Owner: | changed from to | 
|---|---|
| Status: | new → assigned | 
comment:4 by , 7 years ago
| Has patch: | set | 
|---|
comment:5 by , 7 years ago
Patch at:
https://github.com/django/django/pull/10524
I was a little stumped about how to make a regression test for this, since it's checking for an indefinite block on stdin...but I'm happy to try to implement it if someone could help me over that hurdle.
In my testing, it seems that hitting "enter" is necessary to reproduce.