1

I'm making a simple server for my game in Python and I'm using two threads. One thread is looking for new users that wish to connect (for it shall be a MMORPG!) and the other is communicating with users. My problem is this: I can't debug! Or at least, it's very hard because when an error occurs nothing happens! Lets say I write "pint" instead of "print" (which I did, as a test) I would normally get informed and the program would terminate. Now I don't even get informed nor does the program quit. Nothing, and this is making it extremely difficult to locate where errors occur.

I tried using 'ctr+C' but it does nothing, even then the program wont exit, I have to shut down the terminal!

Why is this happening and how can I fix it (or am I doomed)?

yanncore
  • 21
  • 1
  • Check http://stackoverflow.com/questions/47701/is-there-a-way-to-attach-a-debugger-to-a-multi-threaded-python-process and the answers over there - maybe that solves your issue. – Marcel Jackwerth Apr 25 '11 at 14:24
  • You're going to need to post some code (or a lot more detail). "When an error occurs" is not specific enough. What kind of error? A wrong user command? An actual typo in your code? What? Does Ctrl-Break work when Ctrl-C fails? (If that last is true, you most likely have a simple thread deadlock on your hands) – ncoghlan Apr 25 '11 at 16:42
  • I'll second the request for more detail. However, I'm betting that in one or both of your network threads you've got a try/except catchall that is catching your typo exceptions and also catching CTRL+C (KeyboardInterrupt). – stderr Apr 27 '11 at 03:16

1 Answers1

0

I'm not sure about the reason of your problem, but I think you can solve with this:

import sys
...
print >> sys.stderr, 'whatever you want to print'

I use a function for this Debug information with coloured output (DEBUG is a global variable):

def debug(self, *txt):
    if DEBUG:
        print >> sys.stderr, '\033[31m[Debug]:\033[0m ', ' '.join([str(e) for e in txt])
Manuel
  • 2,236
  • 2
  • 18
  • 28
  • I'll see but I don't think that this is the solution to my problem, I can always just normally print. Maybe I'm guessing wrong, because I do not know the purpose of this, could you explain what should this do? – yanncore Apr 25 '11 at 14:20
  • I'm sorry, I'd read that you can't print in standard output (very quick reading, it's my fault). Anyway, you can raise exceptions in each important operation and debug your program – Manuel Apr 25 '11 at 14:54