views:

1944

answers:

5

IDLE's subprocess didn't make connection. Either IDLE can't start a subprocess or personal firewall software is blocking the connection.

Don't think this has been asked-how come this comes up occasionally when running very simple programs-I then have to go to Task Manager & stop all Pythonw processes to get it to work again?

It seems to happen randomnly on different bits of code-here is the one I'm doing at the moment-

f = open('money.txt')
currentmoney = float(f.readline())
print(currentmoney, end='')
howmuch = (float(input('How much did you put in or take out?:')))
now = currentmoney + howmuch
print(now)
f.close()
f = open('money.txt', 'w')
f.write(str(now))
f.close()

Sometimes it works, sometimes it doesn't!

A: 

Can you be more specific by providing a short code sample?

IDLE has some threading issues. So the first thing to debug your problem would be to print some simple stuff in your subprocess. Thereby you will see whether it is a network or threading related issue.

wr
I've added to the question, thanks!
James Wanchai
+1  A: 

In Python 3.0.1, I have gotten that error after I Ctrl-C to interrupt a previous run of a program in Idle's Python Shell and then try to run a script.

Also in 3.0.1: Let's say you have two Idle windows open: a script open for editing in one, and Idle's Python Shell window. I have found that if you close the shell window and then immediately try to run the script, it will give that error when it tries to re-open the shell - but not if you wait a bit in between to let Idle do whatever connection clean up it needs to do.

Worse bugs I have found (again, in v3.0.1- not sure if this would happen in the 2.x versions): I had a long script - getting up towards 9k lines - and once it got to a certain size, doing "save as" on it would crash Idle. I am not sure what the exact threshold was for size - but before that, I would also get some intermittent "save as" crashes that seemed to depend on what else I had going on - other Idle windows, how much output was in the shell window perhaps - stuff like that. It can crash and you will lose unsaved work.

Also - one thing I commonly do is have a scratch window open where I cut and paste bits of code in various stages of validity, write notes to myself, etc - so not a valid python script, but I sometimes save these so I can come back to them. I have one such file that will crash Idle every time I try to open it - and I lost unsaved work the first time. (FYI: Other editors including PythonWin 2.5.2 have no problem opening the file.)

Anon
Sounds pretty similar-I'll keep the ways to get around it in mind, thanks! Is there a way to file a bug report or similar?
James Wanchai
+1  A: 

You can use idle -n to avoid such issues (albeit possibly getting some other limitations).

Alex Martelli
Would you care to elaborate on what this does?I tried to RTFM, but found no mention.http://docs.python.org/3.0/library/idle.html#command-line-usage
Oddthinking
Not sure why it's missing from the docs -- look at the sources, idlelib/PyShell.py in your Python install: -n sets use_subprocess to False, so idle runs the user's code in the same process as the shell and GUI instead of using a subprocess.
Alex Martelli
A: 

If it look like truly random behavior than it could be a multi-cpu/core issue. You could try to set the interpreter affinity to a fixed cpu and see if this issue still comes up.

Google for something like: imagecfg process affinity For more information about that.

Martin P. Hellwig
A: 

Or..you could forget IDLE and try IPython instead. It may not exhibit the same error at all. I've never had a problem with it. You get some cool functionality with it that IDLE doesn't have. I find it very useful when working with Python.

DoxaLogos