1

I've recently got a bug in my pokemon battling bot program i've been writing for some time, which i cannot explain at all.

The code is too long to fit well in a stack overflow question, so here's the entire code in a pastebin.

http://pastebin.com/h4V2DnXh

In short, the code connects to a websocket, receive and send data trough it, and, for me to follow what's happening, print everything it receives. Plus, several debug tools... well, in any case, it prints stuff. Or rather, it used too. For some hours, nothing has been printed. A bug, would I think, the program doesn't reach any line where a print order is issued. But it does ! Everything works, data is correctly sent and received, the data is not empty, the bot does everything it's supposed to do. Thus, I added a

print "test."

at the beginning... and nothing happens... it isn't even about printing empty things, it doesn't print. At all.

By researching, i've found that print bugs could be linked to the usage of IDLE , but i'm using enthought canopy (python 2.7), or that it could be linked to imports, but the print "test." doesn't work, anyway.

Plus, it used to work, and I didn't modify the list of imported modules for a while. And anyway, the modules do not have errors.

I really don't understand. Why won't print work ?

BERNARD Julien
  • 209
  • 1
  • 2
  • 10
  • 1
    how are you running the file? – Padraic Cunningham Dec 31 '14 at 00:28
  • 1
    You should use that _print_ function after modules. – GLHF Dec 31 '14 at 00:29
  • I probably don't understand the question. My file is in my computer, and i simply run it using canopy. – BERNARD Julien Dec 31 '14 at 00:29
  • if you try `python your_file.py` what happens? Obviously from the same directory – Padraic Cunningham Dec 31 '14 at 00:29
  • 1
    @qqvc, that makes no difference at all – Padraic Cunningham Dec 31 '14 at 00:30
  • If I try python SDPlaysCC1v1.py (my file), it works, and print things. So, I guess the issue is relative to Canopy ? About print after or before modules, another question on the site stated print would stop working after importing modules. But the answer was about an IDLE-specific bug. In any case, i tried to put "print test" before and after the imports, none worked. – BERNARD Julien Dec 31 '14 at 00:33
  • 1
    Related? [Enthought Canopy doesn't print right away when statement occurs](http://stackoverflow.com/q/18709659/2359271) – Air Dec 31 '14 at 00:34
  • Possible, it appears to be the same problem ... However, in this link's case, the print end up being printed. Mine do never. I tried creating a file with only one line ' print "test" '. It doesn't print. I'm trying to understand the answer tho, maybe this is actually the same issue. – BERNARD Julien Dec 31 '14 at 00:40
  • @BERNARDJulien, I don't have canopy installed anymore so I cannot test but I would try adding a `sys.stdout.flush()` after the print statements to narrow down the problem and hopefully someone with canopy installed can help you out. There is a related question here also http://stackoverflow.com/questions/25925399/python-enthought-canopy-multiprocessing-not-working – Padraic Cunningham Dec 31 '14 at 00:51
  • So, I tried : import sys (back to line) print "test" (back to line) sys.stdout.flush() And it still does not print anything. (+ damn, i don't know how to put code in comments) – BERNARD Julien Dec 31 '14 at 00:55
  • Hmm, flush is what I would've tried, too. BTW, use backticks at the front and back to get code formatting. `code`. – Ajean Dec 31 '14 at 01:06
  • Have you restarted Canopy? Is it possible you your code does `import sys; sys.stdout=anOpenSocket` in a roundabout way, and now your prints are going somewhere else? – TessellatingHeckler Dec 31 '14 at 01:39
  • I restarted Canopy today, and the prints work again, regardless of the place, the program, or if i use 'sys.stdout.flush()' after the print. ... I don't get it. It appears the prints stop working after several kernel restarts (i'm very often restarting kernel, nearly every reboot), or long usage. When it crashes again, i'll check whether it is necessary to restart only canopy, or the computer. – BERNARD Julien Dec 31 '14 at 11:31

0 Answers0