Skip to content

Python exit handler (ctrl-c) that allows you to set specific "exit points," removing uncertainty when exiting loops.

Notifications You must be signed in to change notification settings

tjmarkham/python-exit-point

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

python-exit-point

Python exit handler (ctrl-c) that allows you to set specific "exit points," removing uncertainty when exiting loops.

Also provides options for custom cleanup functions, exit messages, and debug information.

An "exit point" is a location in your code (typically in a loop) where you feel comfortable terminating your program. Previously, if you pressed "ctrl-c" while a program was executing a loop, there was no way to know where in the loop the program would terminate. Using "exit points," you can set specific points in the loop where a program will terminate.

This is useful in control scenarios where you have loops controlling physical processes that must fully execute before termination.

Importing exitPoint

from exitPoint import exitPoint

Using exitPoint

The "exitPoint" function doesn't require any arguments and can be used by simply placing the following:

exitPoint()

wherever you would like an "exit point" to exist.

For example:

while(True) :
	exitPoint()
	print("Check out this infinite loop!")

The "exitPoint" function has three optional arguments:

  • Debug (if set to True, the name of the program that is exiting is printed before exiting)
  • FunctionToExecute (defines function to execute before exiting)
  • Message (defines message to print before exiting)

Example (Debug on, testFunction will execute before exiting, "Goodbye message!" will print before exiting):

exitPoint(True, testFunction, "Goodbye message!")

About

Python exit handler (ctrl-c) that allows you to set specific "exit points," removing uncertainty when exiting loops.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages