0

I run a script that executes multiple processes, that are executed in different classes. The processes do not end unless the user asks for it. So in the main class I decided to create a process that will exit() the script, I supposed this will kill all the processes too. This is the main.py class.

def finishTest(): end = "notexit" while end != "exit": end = input("To finish the test type 'exit'") exit() if __name__ == '__main__': fT = Process (target=finishTest) fT.start() #this are functions of this class that call functions from other classes that run the other processes. askTest() execTest() 

When I execute the main.py the following error appears,

Traceback (most recent call last): File "/usr/lib/python3.7/multiprocessing/process.py", line 297, in _bootstrap self.run() File "/usr/lib/python3.7/multiprocessing/process.py", line 99, in run self._target(*self._args, **self._kwargs) File "execution.py", line 20, in finishTest exit = input("To finish the test type 'exit'") EOFError: EOF when reading a line 

How do I correct this error? Isn't it this a correct way to stop a script and all the processes being executed by the script?

Thank you all!

9
  • First of all you should think about renaming your exit variable (as exit is a pre-existing function), second, I don't think the issue is in the function you shared here (finishTest()) - just tried running it alone and aside from an error on the exit function it works fine Commented Mar 14, 2019 at 9:26
  • @DirtyBit if the user types "exit" in the prompt, then exit will be set to "exit" Commented Mar 14, 2019 at 9:27
  • @JessicaChambers Nope, it would throw an error: exit() TypeError: 'str' object is not callable Commented Mar 14, 2019 at 9:28
  • Because the variable name is the same as the function name, hence my comment about renaming the variable. In either case I don't recieve the EOF error Commented Mar 14, 2019 at 9:29
  • with some tweaks I have this which runs error free: ``` my_exit = "notexit" while my_exit != "exit": my_exit = input("To finish the test type 'exit'") print("bye bye!") ``` Commented Mar 14, 2019 at 9:29

1 Answer 1

0

Change the variable exit name and try putting it in a try-except block:

def finishTest(): ex = "notexit" while ex != "exit": try: ex = input("To finish the test type 'exit'") except EOFError: pass exit() 

OUTPUT:

To finish the test type 'exit'hey To finish the test type 'exit'okay To finish the test type 'exit'bye To finish the test type 'exit'exit Process finished with exit code 0 
Sign up to request clarification or add additional context in comments.

8 Comments

This corrects the EOFError but logically executes an infinite loop. I get out the print message out of the while loop, it seems that works fine but the script doesn't stop.
@Nkolot It does not, added a sample output.
I get out the print message out of the while loop, it seems that works fine but the script doesn't stop.
Which script does not stop? What do you get?
Thank you for your help, I will look it and stake out the way to finish the processes.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.