Python Daemons - Program Structure and Exception Control -
i've been doing amateur coding in python while , feel quite comfortable it. though i've been writing first daemon , trying come terms how programs should flow.
with past programs, exceptions handled aborting program, perhaps after minor cleaning up. consideration had give program structure effective handling of non-exception input. in effect, "garbage in, nothing out".
in daemon, there outside loop never ends , sleep statement within control interval @ things happen. processing of valid input data easy i'm struggling understand best practice dealing exceptions. exception may occur within several levels of nested functions , each needs return parent, must, in turn, return parent until control returns outer-most loop. each function must capable of handling exception condition, not subordinates.
i apologise vagueness of question i'm wondering if offer me general pointers how these exceptions should handled. should looking @ spawning sub-processes can terminated without impact parent? (remote) possibility i'm doing things correctly , need nested handling. real possibility haven't got clue i'm talking about. :)
steve
exceptions designed purpose of (potentially) not being caught immediately-- that's how differ when function returns value means "error". each exception can caught @ level want (and can) it.
at minimum, start catching exceptions @ main loop , logging message. simple , ensures daemon won't die. @ main loop it's late fix problems, can catch specific exceptions sooner. e.g. if file has wrong format, catch exception in routine opens , tries use file, not deep in parsing code problem discovered; perhaps can try format. if there's place recover particular error condition, catch there , so.
Comments
Post a Comment