Discussion:
[Twisted-Python] suggestions sought on multi-service application dealing with shared database issue
Glyph Lefkowitz
2017-01-17 10:08:03 UTC
Permalink
* an application defined in a `.tac` file that is an instance of `twisted.application.service.Application`
* multiple user-defined services (IIRC 8 or 9) that are subclasses as twisted.application.internet.TimeService
* the services are added to the application via `setServiceParent`
* the reactor is started via `twisted.internet.reactor.run()`
I've run into an annoying issue a few times, and need to temporarily suspend all/most of the services from running... an internal backup script occasionally breaks (on a new edge case every time we fix it) and ends up consuming 100% of disk space. This cascades into database failures in my application.
I've got an external service monitoring disk-space and alerting me. It's presently shutting down the twisted daemon when the error happens, but I'd like to keep twisted running and just adapt to the server conditions.
1. Create a new service that monitors server conditions and can call stopService/startService on registered services as needed
2. Keep all the services running, but put a conditional check in the timer service's callable
has anyone preferred one of these, or something different, in the past?
It depends if it's easier to keep track of when changes happen, or determine what the current state is.

If it's easier to keep track of when changes happen, I would recommend calling `setServiceParent` to add/remove the service to the active service hierarchy. (This will call `startService` / `stopService` for you automatically, as well as cooperating with things like ^c so it's better than calling them yourself).

If it's easier to query the current state, then a conditional in the timer is a lot simpler.

-glyph
Glyph Lefkowitz
2017-01-17 23:42:02 UTC
Permalink
Can you point to some docs about setServiceParent being used to remove the service? I couldn't find that anywhere.
Sorry, I meant you should use https://twistedmatrix.com/documents/16.6.0/api/twisted.application.service.IService.html#disownServiceParent <https://twistedmatrix.com/documents/16.6.0/api/twisted.application.service.IService.html#disownServiceParent> disownServiceParent.

-glyph

Loading...