Opened 15 years ago

Closed 15 years ago

#10341 closed (duplicate)

Project module loaded twice

Reported by: rginda@… Owned by: nobody
Component: Uncategorized Version: 1.0
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I have some initialization code in my project's __init__.py (the one from the same directory as settings.py), and I've notice that it's executed *twice* for each thread. I added the following lines to my __init__.py...

  print "*** thread: %s, %s" % (thread.get_ident(), __name__)
  traceback.print_stack()

And found...

$ ~/dist/mark1/bin/mark1-django-ctl.sh runserver ginda1:8080
*** thread: -1208932672, mark1
  File "manage.py", line 6, in <module>
    import mark1.settings
  File "/home/au/au10010/dist/mark1/django/mark1/__init__.py", line 53, in <module>
    traceback.print_stack()
*** thread: -1208932672, mark1.
  File "manage.py", line 14, in <module>
    execute_manager(mark1.settings)
  File "/opt/ark/sw/python2.6/lib/python2.6/site-packages/django/core/management/__init__.py", line 338,
 in execute_manager
  File "/opt/ark/sw/python2.6/lib/python2.6/site-packages/django/core/management/__init__.py", line 316,
 in setup_environ
  File "/home/au/au10010/dist/mark1/django/mark1/__init__.py", line 53, in <module>
    traceback.print_stack()

It seems like it's loaded for the first time when manage.py loads the settings file, and second time from <http://code.djangoproject.com/browser/django/trunk/django/core/management/__init__.py#L331>.

Notice that the second time it's loaded, the module is called 'mark1.', rather than just 'mark1'. If I switch the management code to...

    __import__(project_name)
    project_module = sys.modules[project_name]

...then my module is only loaded once.

Change History (1)

comment:1 by Alex Gaynor, 15 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #8193.

Note: See TracTickets for help on using tickets.
Back to Top