Am Montag, 5. November 2007 10:55 schrieb Malcolm Tredinnick:
> On Mon, 2007-11-05 at 10:46 +0100, Thomas Güttler wrote:
> > Hi,
> >
> > settings.py gets imported twice. This is bad, if you want to
> > set up the logging module, since you register the handler twice
> > and you get all log messages twice.
>
> [...]
>
> It's actually fairly hard to avoid this for a variety of reasons. I
> think we used to import it more than twice in some situations. Maybe we
> still do. User-defined commands and processing the --settings option
> becomes more fiddly, for example. So the answer is "don't rely on it
> only being imported once".

OK,

maybe it should be documented.

The usual way to use global variables with a different module:
http://effbot.org/pyfaq/how-do-i-share-global-variables-across-modules.htm

did not work for me, since the modul gets imported with different __name__'s.

The first time __name__ is 'logconfig' the second time it is 
'myproject.logconfig'.


A found this solution.

# file logconfig.py
import logging
if not hasattr(logging, "set_up_done"):
    logging.set_up_done=False

def set_up(myhome):
    if logging.set_up_done:
        return
    logging.set_up_done=True


 Thomas

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to