Calling get_current_registry() during Pyramid startup

186 views
Skip to first unread message

Andreas Jung

unread,
Jan 29, 2013, 3:24:53 AM1/29/13
to pylons-...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I have a method

def notify(text):
settings = pyramid.threadlocal.get_current_registry().settings
host = settings.get(....)

which works fine when called from a view.

However when I call this method during the startup phase
from the main() method of my app then 'settings' evaluates to None.

I have seen that my code is working also during the startup phase
with Kotti but not within a bare Pyramid application...any trick
I am missing?

Andreas
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQGUBAEBAgAGBQJRB4dUAAoJEADcfz7u4AZj0dgLv0Kv6GEVLhzklUfDhbVs1tXD
YJPirBbB08lG0l/bk24mh8HfHjahR4FUNavKNGggFXWYAiqM6LuTpn6GSlud/IQB
hodjjGFSF4EoMTVPt8NiuCIZaGOJnPvYXmlkPOchPydQn3Tvf9oL9aANje1G0Pvl
vWU9lol8nJ3xNvm/TbaUVXB3mNlKOaJGMOLLHa36WAiE8xrRV2JwlgD6e1V4hZqS
TXRyzSYXAsUdImW/kJDXubA03/+mv+fC1nWIJmd0sc1A7cI43U6DkMXuMVVnfk5l
5/pjUU1TeHDoRBYQBTrtSDIQ/ETUxC983rNdxW70gIwPjhRJjGC2QIE5PessDuqO
gE81ezuHnFW60BUFzdr9oZZz6JwmHEW3m9GbcEgVT7jjxYovp/6CUMdh5WaKe/UR
En7J7StoRCzk/FOKQs+pVVpI9Og+G9gGXIf67pQvy7CEVSGDLzGykBm7oIz0oH+d
AjPsBI+G37prR+Jv3dmE8HJjQSHs0As=
=kKfJ
-----END PGP SIGNATURE-----
lists.vcf

Andreas Kaiser

unread,
Jan 29, 2013, 4:45:28 AM1/29/13
to pylons-...@googlegroups.com

On 29.01.2013, at 09:24, Andreas Jung <li...@zopyx.com> wrote:

> I have a method
>
> def notify(text):
> settings = pyramid.threadlocal.get_current_registry().settings
> host = settings.get(....)
>
> which works fine when called from a view.
>
> However when I call this method during the startup phase
> from the main() method of my app then 'settings' evaluates to None.
>
> I have seen that my code is working also during the startup phase
> with Kotti but not within a bare Pyramid application...any trick
> I am missing?

Within main() you usually have a config object that has a get_settings()
method.

You should almost never use pyramid.threadlocal.get_current_registry()
in application code if there's another way to get the registry (such as
e.g. request.registry in a view).

Also see http://docs.pylonsproject.org/projects/pyramid/en/latest/api/threadlocal.html#pyramid.threadlocal.get_current_registry.


HTH,

Andreas

Jonathan Vanasco

unread,
Jan 29, 2013, 10:56:34 AM1/29/13
to pylons-discuss


On Jan 29, 4:45 am, Andreas Kaiser <di...@binary-punks.com> wrote:
> On 29.01.2013, at 09:24, Andreas Jung <li...@zopyx.com> wrote:
> > However when I call this method during the startup phase
> > from the main() method of my app then 'settings' evaluates to None.
>
> You should almost never use pyramid.threadlocal.get_current_registry()
> in application code if there's another way to get the registry (such as
> e.g. request.registry in a view).

Could this be implemented withinin an event ? There is an
ApplicationCreated event http://docs.pylonsproject.org/projects/pyramid/en/1.3-branch/api/events.html

Wyatt Baldwin

unread,
Jan 29, 2013, 1:10:59 PM1/29/13
to pylons-...@googlegroups.com, li...@zopyx.com
On Tuesday, January 29, 2013 12:24:53 AM UTC-8, Andreas Jung wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I have a method

def notify(text):
    settings = pyramid.threadlocal.get_current_registry().settings
    host = settings.get(....)

which works fine when called from a view.

However when I call this method during the startup phase
from the main() method of my app then 'settings' evaluates to None.

I have seen that my code is working also during the startup phase
with Kotti but not within a bare Pyramid application...any trick
I am missing?

You probably don't want to use thread locals for this. Can you just pass the relevant settings to the function?

If you really want to use thread locals, you could push the config's registry onto the thread local stack in main() before you call notify().
Reply all
Reply to author
Forward
0 new messages