ProgramShutdown
35
itly provide the timede lay as an argument. If this is done, the argument should express the number of
full or partial seconds as a floating point value.
Using a timede layis a useful starting point, as itpr ovidesa means of defining an upper bound on the
amount of time you wish to allow the system to run before it is stopped. Having a small delay and en-
suring everything is done in that time is preferable, as in certain circumstances such as the operating
system sending a SIGTERM to an application on system shutdown, the operating system will usually
forcibly shutdown your application using SIGKILL after 5 seconds if it doesn’t do so of its own ac-
cord.
Although getting away from the goal of having only one mechanism for shutting down a program, in
this circumstance,it may still be preferable to separately identify a SIGTERM signal and deal with it
differently. Here you mightonly do anything that is absolutely essential and stop the process immedi-
ately. What is the best approach will depend on the specific applicationin question.
If the problemof a SIGTERM s ignal isignored, a further mechanism for delaying actual shutdown of
a process is also provided.I fupon receiving notification of a pending shutdown, an agent knows it
needsto wait f or some event to occur first, it can call the "suspendShutdown()" member function.
If thisis done,although the shutdown delay may expire, actual program s hutdownw illnot occ uruntil
a corresponding call to the "resumeShutdown()" member function. If more than one agent calls
"suspendShutdown()", actual shutdown will not occur until "resumeShutdown()" has been
called a matching number of times.
Although it is possibleto suspend thes hutdown process in thiswa y,it is notpossible to ca ncel it com-
pletely. But then, if an agent doesn’t call "resumeShutdown()" at some point it wouldne veractu-
allyoccur. This wouldn’t bevery useful however, as more than likely parts of the application m ay have
placed themselves into a dormant state.
Finally, ass cheduling programshutdown upon a signal occur ringwould be done in practically all pro-
grams, support for this has been factored into the actual dispatcher. Thus, instead of dedicating a spe-
cific agent to catch any signals, the main program file can contain:
dispatcher = netsvc.Dispatcher()
dispatcher.monitor(signal.SIGINT)
dispatcher.monitor(signal.SIGTERM)
If this interface is used however, the only means of overriding the delay between shutdown being
scheduled and actual shutdown is by the OTCLIB_SHUTDOWNDELAY environment variable.
The dispatcher also provides the member function "shutdown()". This behaves much the same as
the "scheduleShutdown()" member function of the Agent class. The presence of the "shut-
down()" member function inthe dispatcher, allows code which is distinct from an agent to also
schedule a program shutdown.