Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Post Run Hook Not Executing in Cement 2.7.x #328
Ran into a strange situation when defining a custom base controller.
Running the app:
with PubKeyApp() as app: app.run() try: app.run_forever() # custom function added in my class except (KeyboardInterrupt, SystemExit, CaughtSignal): app.log.info('Shutting down pubkey REST server')
Simple base controller:
class PubKeyBaseController(CementBaseController): class Meta: label = 'base' description = "pubkey - Public Key distribution made easy" arguments = [ (['-a', '--auto'], dict(action='store_true', help='auto detect IP address')), ]
Part of the App class:
class PubKeyApp(CementApp): class Meta: label = 'pubkey' config_defaults = defaults base_controller = 'base' config_handler = 'config_handler' handlers = [PubKeyBaseController, PubKeyConfigHandler] arguments_override_config = True def setup(self): # always run core setup first super(PubKeyApp, self).setup() self.log.debug('running setup()') self._loop = asyncio.get_event_loop() hook.register('post_run', self._post_run) hook.register('pre_close', self._pre_close) def _post_run(self, app): self.log.debug('running _post_run()') self._loop.run_until_complete(self._init(self._loop)) def _pre_close(self, app): self.log.debug('running _pre_close()') self._loop.run_until_complete(self._finish()) @asyncio.coroutine def _init(self, loop): self.log.debug('running _init()') ...
On 2.6.x here is a sample output of a simple app that registers multiple hooks - one of them a post_run hook and executes the hook as expected.
On the latest 2.7.x installed from github repo the same program without changes still registers the post_run hook but it never gets called (should come right after post_argument_parsing) - hence missing a significant portion of this particular app.
Interestingly other hooks like _pre_close() execute on both versions as expected.
Without the custom base controller the post_run hook gets executed on both 2.6.x as well as 2.7.x. If I comment out the base controller on 2.7.x the post_run hook executes as expected.
Hope this helps!