Execute code after instance initialization

13 views
Skip to first unread message

Bastien Sevajol

unread,
May 30, 2016, 4:00:05 AM5/30/16
to TurboGears
Hi,

I need to execute code once my application is itilialized and ready to use (auth methods usage, etc).
Place my code in tg.configuration.app_config.AppConfig#after_init_config is right place ?

To expose my situation: I want to launch in subprocess, a radicale server instance who use my app auth methods.

Thank's,
Bastien.

Bastien Sevajol

unread,
May 30, 2016, 4:25:15 AM5/30/16
to turbo...@googlegroups.com
Or maybe afterapp creation using make_base_app ?
make_base_app = base_config.setup_tg_wsgi_app(load_environment)
Regards,
Bastien.
--
You received this message because you are subscribed to a topic in the Google Groups "TurboGears" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/turbogears/31iXx6bwFdM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to turbogears+...@googlegroups.com.
To post to this group, send email to turbo...@googlegroups.com.
Visit this group at https://groups.google.com/group/turbogears.
For more options, visit https://groups.google.com/d/optout.

Alessandro Molina

unread,
May 30, 2016, 4:39:44 PM5/30/16
to TurboGears
Usually the best way to achieve this is:

- Through the environment_loaded milestone if you need it to happen once per process ( http://turbogears.readthedocs.io/en/latest/turbogears/configuration/appconfig.html#configuration-milestones )
- Through the configure_new_app hook if you need it to happen once for each TG application created by a process ( http://turbogears.readthedocs.io/en/latest/turbogears/hooks.html#available-hooks

--
You received this message because you are subscribed to the Google Groups "TurboGears" group.
To unsubscribe from this group and stop receiving emails from it, send an email to turbogears+...@googlegroups.com.

Bastien Sevajol

unread,
Jun 7, 2016, 4:04:28 AM6/7/16
to turbo...@googlegroups.com
Thank you, i choosed environment_loaded milestone entry point.
Regards,
Bastien Sevajol.
You received this message because you are subscribed to a topic in the Google Groups "TurboGears" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/turbogears/31iXx6bwFdM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to turbogears+...@googlegroups.com.

Damien Accorsi

unread,
Jun 7, 2016, 3:00:50 PM6/7/16
to turbo...@googlegroups.com
Hi Alessandro,

By investigationg with Bastien about threading in turbogears, we found that tgext.asyncjob worker thread is not stopped gracefully. (the code includes a raw "while True".
Would you be interested in us to implement a gracefull stop of the thread ?

Currently in case of long-term asynchronous operations (especially writing in database), this may result in dirty/unexpected data/behavior.

If so, where is the original repo of tgext.asyncjob ? https://bitbucket.org/axant/tgext.asyncjob ?


Damien

Alessandro Molina

unread,
Jun 7, 2016, 3:11:07 PM6/7/16
to TurboGears
That's right, tgext.asyncjob starts the thread in daemon mode, so there is no guarantee that your thread will finish in a clear way.
Whenever the master process terminates, the thread does too.

That was the choice made as the worker is bound to the application process and I didn't want to have the application block waiting for the worker to complete during a restart as the use case for asyncjob was mostly related to transient/idempotent tasks like exporting a file to user.

I'll gladly review and merge any patch to add graceful shutdown of the worker. Just make sure it's optional for anyone willing to keep the current quick shutdown behaviour.

Reply all
Reply to author
Forward
0 new messages