phatgamer69
phatgamer69

Reputation: 3

Python Testing with Kill Process

When testing a Python script I will often use a 'raw_input()' or 'input()' as a marker in the script, and when that marker is reached do a ctrl + c to kill the process in my command prompt.

I was worried this would lead to memory leaks, this brief thread indicates it shouldn't - killing python process leads memory leak?

It is bad practice to test scripts this way? Can it lead to any negative effects?

Upvotes: 0

Views: 408

Answers (2)

GIZ
GIZ

Reputation: 4643

Usually there's no problem with using raw_input() or input() with ctrl + c to terminate your program. When you press ctrl+ c during raw_input or input invocation you're just raising a KeyboardInterrupt exception and Python knows how to handle exceptions appropriately. If you don't handle the KeyboardInterrupt, this exception will be handled by the default top-level exception handler, this default exception handler prints the stack trace from which the exception occurred just before exiting the interpreter.

For some applications, they might not free their resources after they exit or after you kill the process, most operating systems today are smart enough to free memory when its unused. But this is not applicable to your question.

Upvotes: 1

pointerless
pointerless

Reputation: 753

Not sure about the leaks but I'm sure breakpoints are your friend here. In idle right click on the line you want to stop on and click set breakpoint, then clear when you're finished debugging.

Upvotes: 0

Related Questions