Opened 7 years ago

Closed 7 years ago

Last modified 6 years ago

#27657 closed Bug (needsinfo)

Getting crash when using the runserver command on Windows 10 in PowerShell following update to Python 3.6

Reported by: horatius83 Owned by: nobody
Component: Utilities Version: 1.10
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Any time I run the command python .\manage.py runserver Python crashes. This behavior only seems to occur in PowerShell (even in Admin mode) but it runs fine in the regular command line.

PS C:\Users\Tyler Durden\Documents\GitHub\debt_calculator> python -u -m trace -t .\manage.py runserver >> ./python_error.log
Traceback (most recent call last):
  File "C:\Users\Tyler Durden\AppData\Local\Programs\Python\Python36-32\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Users\Tyler Durden\AppData\Local\Programs\Python\Python36-32\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\Tyler Durden\AppData\Local\Programs\Python\Python36-32\lib\trace.py", line 742, in <module>
    main()
  File "C:\Users\Tyler Durden\AppData\Local\Programs\Python\Python36-32\lib\trace.py", line 730, in main
    t.runctx(code, globs, globs)
  File "C:\Users\Tyler Durden\AppData\Local\Programs\Python\Python36-32\lib\trace.py", line 469, in runctx
    exec(cmd, globals, locals)
  File ".\manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Users\Tyler Durden\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\management\__init__.py", line 367, in execute_from_command_line
    utility.execute()
  File "C:\Users\Tyler Durden\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\management\__init__.py", line 330, in execute
    autoreload.check_errors(django.setup)()
  File "C:\Users\Tyler Durden\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\management\base.py", line 294, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Users\Tyler Durden\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\management\commands\runserver.py", line 58, in execute
    super(Command, self).execute(*args, **options)
  File "C:\Users\Tyler Durden\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\management\base.py", line 345, in execute
    output = self.handle(*args, **options)
  File "C:\Users\Tyler Durden\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\management\commands\runserver.py", line 97, in handle
    self.run(**options)
  File "C:\Users\Tyler Durden\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\management\commands\runserver.py", line 106, in run
    autoreload.main(self.inner_run, None, options)
  File "C:\Users\Tyler Durden\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\utils\autoreload.py", line 333, in main
    reloader(wrapped_main_func, args, kwargs)
  File "C:\Users\Tyler Durden\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\utils\autoreload.py", line 304, in python_reloader
    exit_code = restart_with_reloader()
  File "C:\Users\Tyler Durden\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\utils\autoreload.py", line 285, in restart_with_reloader
    args = [sys.executable] + ['-W%s' % o for o in sys.warnoptions] + sys.argv
TypeError: can only concatenate list (not "tuple") to list

Change History (4)

comment:1 by Tim Graham, 7 years ago

So sys.argv is the tuple, I guess? It doesn't seem that Django is necessarily at fault. Could you investigate the issue a bit more to determine what's causing it to be a tuple rather than a list?

comment:2 by horatius83, 7 years ago

I have established that PowerShell is not passing in the arguments as tuples by running just args = [sys.executable] + ['-W%s' % o for o in sys.warnoptions] + sys.argv in a small script.

I have no experience in debugging large Python programs. My naive approach would be to run up the stack trace, setting breakpoints and trying to establish if sys.argv is getting mutated somewhere. Ideally I'd like to set a breakpoint in a setter of some kind, if that's even possible. Is there a more elegant approach to this? (Laziness is a virtue, at least that's what the Haskellers tell me)

comment:3 by Tim Graham, 7 years ago

Resolution: needsinfo
Status: newclosed

I'm not sure, this probably isn't the best channel to get help since Windows and changes in Python aren't our expertise. By the way, I just tried this and I can't reproduce it (printing sys.argv right above the place that crashed for you shows ['.\\manage.py', 'runserver'] (tested with Windows 10, Python 3.6, Windows PowerShell). Feel free to reopen the ticket if you investigation concludes that Django must adapt in some way.

comment:4 by Walter Doekes, 6 years ago

Found this particular problem, I think:

$ python3.5 -m trace --trace <(echo 'import sys; print(repr(sys.argv))')
 --- modulename: 63, funcname: <module>
63(1): ['/dev/fd/63']
 --- modulename: trace, funcname: _unsettrace
trace.py(77):         sys.settrace(None)

vs.

$ python3.6 -m trace --trace <(echo 'import sys; print(repr(sys.argv))')
 --- modulename: 63, funcname: <module>
63(1): ('/dev/fd/63',)
 --- modulename: trace, funcname: _unsettrace
trace.py(77):         sys.settrace(None)

It's the trace module in py3.6 that turns the argv into a tuple.

Not a Django bug.

$ python3.6 -V
Python 3.6.1
Note: See TracTickets for help on using tickets.
Back to Top