I'm trying to keep my python program running but it closes right away. I have tried raw_input()
but I get this error: EOFError: EOF when reading a line
I put raw_input()
at the end. What should I use to have it running?

- 513
- 2
- 8
- 19
-
1Do you mean prevent the console from closing? Otherwise, to keep it running use some sort of infinite loop. – Levon Apr 14 '13 at 20:40
-
@Levon Yes I thought about loop but what kind of loop will not use CPU and can safely used? – Mark Apr 14 '13 at 20:40
-
You could use a loop and put a sleep call into it to "suspend" the program periodically assuming that doesn't interfere with the functionality you are trying to achieve. – Levon Apr 14 '13 at 20:41
-
@Mark you can use `time.sleep()` – Ashwini Chaudhary Apr 14 '13 at 20:41
-
@Levon that will be alright, do you mind proving the code? So I can accept as an answer? – Mark Apr 14 '13 at 20:42
-
@Ashwini time.sleep() sometime will end so it will not keep it for ever alive right?... – Mark Apr 14 '13 at 20:43
-
@Mark yes it'll end sometime, but you can place it in a while loop.`while True:time.sleep(100000)` – Ashwini Chaudhary Apr 14 '13 at 20:45
-
@Ashwini adding this to end will work? No cpu 100%? – Mark Apr 14 '13 at 20:48
-
@Mark Yes, no 100% CPU load. – Ashwini Chaudhary Apr 14 '13 at 20:50
2 Answers
What you want to do is compile an EXE using py2exe specifying that it's a console app. This is why you're getting an EOF error, there's no stdin for raw_input()
to read from.
Create a setup.py like this:
from distutils.core import setup
import py2exe
setup(console=['your_script.py'])
Then you can just compile it by running this in a console window:
python setup.py py2exe
This will produce your_script.exe in that directory which should stay open as a console window if you have a raw_input()
at the end of your script.
Make sure setup.py and your_script.py are in the same directory and that you have py2exe installed.
For reference, you can get py2exe online.
Incidentally, this also allows you to use commandline arguments in your py2exe programs.

- 1
- 1

- 192
- 2
- 7
I don't have access to Python right now, but something like
from time import time, sleep
while True:
#do other stuff
sleep(5)
should be close. This would sleep for 5 seconds each time through the loop, see the docs for time.sleep() . Adjust the time to fit your needs.

- 138,105
- 33
- 200
- 191
-
1@downvoter .. why the downvote? OP seems satisfied with the answer. Downvotes w/o explanation help no one, OP, SO or me. – Levon Apr 15 '13 at 10:13