[Mark Hammond] >>> However, a service can stop also stop by its own accord.
[Tim Peters] >> I don't think ZRS ever does that, and am not sure how I could write >> code to do it. Does a Zope service ever decide to "stop by its own >> accord"? [Mark Hammond] > By that, I simply mean "terminate with a zero exit code". Obviously not "of > its own accord", but it has nothing to do with the service framework. This > also includes "terminate with non-zero exit code too many times" - you will > not be called in this case either. >>> The question, then, is under what cases should the onStop() >>> calls be made? It sounds to me like you want it called only when that >>> external request comes in. >> Maybe. In the end, by whatever means a service gets shut down >> (external, internal, whatever), I want to see the subclass onStop() >> method called exactly once. > My patch does not do that. If Zope terminates "of its own accord", then > your hook is never called. This means that patch is suitable if you need > onStop to actually trigger the stop process, but not to be notified of > normal shutdown. > > Having that method called exactly once in all circumstances is a little more > tricky, and would probably involve a maintaining a flag - it must be called > in SvcStop to *trigger* the shutdown, or if shutdown is "normal" (ie, not > triggered by us), then it must be called as the main run-loop terminates - > but not both times. >> Seems to work fine for the ZRS-related services too, although I didn't >> get into the "restarting too frequently" branch. Thank you. If >> nobody objects in the next 10 minutes, then, I'll check this in (and >> port to Zope trunk (2.8) too). > I did test the "too frequently" branch - but note that as above, that patch > will *not* have your function be called when Zope just sys.exits. If that > is suitable, go for it :) Bet you were wondering when you'd see new text <wink>. Thing is, ZRS has nothing in particular to do with Zope. It runs independently of Zope, and may run on boxes that don't even have a Zope installed. It has no UI at all, it's just a couple of services that run infinite loops. The only way it stops on Windows is as a result of someone clicking "stop" in the Windows Services GUI, or by running "XYZservice.py stop" from a DOS box, or by getting a stop request via, e.g., Windows shutdown. In those cases I want onStop() called exactly once, and that's what's happening now, so I'm happy. AFAICT, the ZRS services are the only ones we have that override onStop(); if so, there's no other case to look at. Good enough for now, anyway! _______________________________________________ Zope-Checkins maillist - Zope-Checkins@zope.org http://mail.zope.org/mailman/listinfo/zope-checkins