4

Whenever I try to debug Django's manage.py from Eclipse I get:

pydev debugger: warning: psyco not available for speedups (the debugger will still work correctly, but a bit slower)
pydev debugger: starting
Traceback (most recent call last):
  File "/proj/virtualenvs/testing/infocards/manage.py", line 15, in <module>
    execute_manager(settings)
  File "/proj/virtualenvs/testing/lib/python2.6/site-packages/django/core/management/__init__.py", line 438, in execute_manager
    utility.execute()
  File "/proj/virtualenvs/testing/lib/python2.6/site-packages/django/core/management/__init__.py", line 379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/proj/virtualenvs/testing/lib/python2.6/site-packages/django/core/management/base.py", line 191, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/proj/virtualenvs/testing/lib/python2.6/site-packages/django/core/management/base.py", line 220, in execute
    output = self.handle(*args, **options)
  File "/proj/virtualenvs/testing/lib/python2.6/site-packages/django/core/management/commands/runserver.py", line 67, in handle
    self.run(*args, **options)
  File "/proj/virtualenvs/testing/lib/python2.6/site-packages/django/core/management/commands/runserver.py", line 76, in run
    autoreload.main(self.inner_run, args, options)
  File "/proj/virtualenvs/testing/lib/python2.6/site-packages/django/utils/autoreload.py", line 131, in main
    reloader(main_func, args, kwargs)
  File "/proj/virtualenvs/testing/lib/python2.6/site-packages/django/utils/autoreload.py", line 104, in python_reloader
    reloader_thread()
  File "/proj/virtualenvs/testing/lib/python2.6/site-packages/django/utils/autoreload.py", line 83, in reloader_thread
    ensure_echo_on()
  File "/proj/virtualenvs/testing/lib/python2.6/site-packages/django/utils/autoreload.py", line 77, in ensure_echo_on
    attr_list = termios.tcgetattr(fd)
termios.error: (22, 'Invalid argument')
Validating models...

Running python manage.py runserver from the command line works fine.

Googling around I found that the termios.error: (22, 'Invalid argument') error is because python is trying to read from stdin but cannot from inside the Eclipse environment.

[Edit]: I forgot to mention that I am running PyDev and the latest 1.3 version of Django.

[Edit]: @Blake, @izhak. I Eclipse I have defined the Python included in my virtualenv (/proj/virtualenvs/testing as you can see from the output). From the command line I use the same Python version as I have activated the virtualenv.

stratosgear
  • 942
  • 1
  • 16
  • 37

6 Answers6

3

Seems like lack of --noreload causes this effect. Weird.

EDIT: First I thought it was the working directory of the project.

julx
  • 8,694
  • 6
  • 47
  • 86
  • Thank you. Adding --noreload fixed the problem. I just have to remember to restart the server on any code changes. – stratosgear Apr 08 '11 at 20:05
  • If you ever find a solution to avoid `--noreload` other than running everything from the command line, please let me know. – julx Apr 08 '11 at 20:24
  • For getting autoreload to work, check out: http://djangosnippets.org/snippets/1561/ However, after pasting this code in and removing `--noreload` it still doesn't work. If I leave `--noreload` as is, I still get this error :/ Django 1.3. – Tuukka Mustonen Jun 15 '11 at 13:30
  • I've checked this code and it doesn't work for me. It complains about not being able to connect to some port. However if I leave `--noreload` in place it goes on as usual. – julx Jun 15 '11 at 13:57
  • Sorry, I wrote it the wrong way around. I meant: using that snippet and `--noreload` has no effect (no auto-reload). Using that snippet without --noreload gives the error trace you originally posted in your question. – Tuukka Mustonen Jun 17 '11 at 08:03
2

Spend 3+ hours figuring out this problem. Basically the culprit is with the django 1.3's autoload.py file. Basically the Eclipse's stdin is not tty type of device. the Hack to this problem is to modify /your-path-to-django/util/autoreload.py like this:

index e5a421e..1a4a1a1 100644
--- a/autoreload_bak.py
+++ b/usr/local/lib/python2.6/dist-packages/django/utils/autoreload.py
@@ -73,11 +73,12 @@ def code_changed():

 def ensure_echo_on():
     if termios:
-        fd = sys.stdin.fileno()
-        attr_list = termios.tcgetattr(fd)
-        if not attr_list[3] & termios.ECHO:
-            attr_list[3] |= termios.ECHO
-            termios.tcsetattr(fd, termios.TCSANOW, attr_list) 
+        if sys.stdin.isatty():
+            fd = sys.stdin.fileno()
+            attr_list = termios.tcgetattr(fd)
+            if not attr_list[3] & termios.ECHO:
+                attr_list[3] |= termios.ECHO
+                termios.tcsetattr(fd, termios.TCSANOW, attr_list)

 def reloader_thread():
     ensure_echo_on()

This should allow you to run runserver in Eclipse even without --noreload option.

Note: You still need to apply this patch in order to get rid of child/parent process problem, see here: How to enable Eclipse debugging features in a web application?

Community
  • 1
  • 1
Tony Tan
  • 29
  • 2
1

I had the exact same error when I tried to simply run a django program from Eclipse. If I right-clicked on the project, then selected Django -> Custom Command, and 'runserver', it would fail. I finally found out that by clicking on the Run button on the Eclipse toolbar, it would work. Even there though, I've found that it's not always a sure thing. I am running the latest PyDev, 2.0. As with you, running it from the command line outside of eclipse worked every time.

Paul
  • 149
  • 1
  • 3
0

Have you tryed installing PyDev plugin for Eclipse? It really makes easy for Eclipse users to develop Python apps and especially Django apps. Just create new Django project and you will get well configured environment and manage.py available for running from project context menu.

lithuak
  • 6,028
  • 9
  • 42
  • 54
  • Yes, of course I have PyDev installed. I get the same error whether I define my debug configuration as a "PyDev Django" configuration or a "Python Run" one... – stratosgear Apr 06 '11 at 21:24
0

Do you have more than one version of Python on your system? If the version opened from the terminal is different that the version the PyDev interpreter is using, that could be causing problems / differences in operating environment.

Blake
  • 841
  • 4
  • 13
0

Can you check in Eclipse>Windows>preferences>Pydev >Python for the python versionu u use. Give the exact python version u use there.

rv_k
  • 2,383
  • 7
  • 39
  • 52