Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9273871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:12:57+00:00 2026-06-18T16:12:57+00:00

We have a server that is configured to run a pyramid+sqlalchemy app with modwsgi+apache2

  • 0

We have a server that is configured to run a pyramid+sqlalchemy app with modwsgi+apache2

We have a few things in the __init__.py of the pyramid app to create database and prepopulate some test users and accounts. It is similar to the initialize_sql function in pyramid cookbook example here

Out apache config looks something like this (Copied from somewhere and hacked):

WSGIApplicationGroup %{GLOBAL}
WSGIPassAuthorization On
WSGIDaemonProcess pyramid user=ubuntu group=staff processes=1 \
   threads=4 \
   python-path= VIRTUAL_ENV_SITE_PACKAGES
WSGIScriptAlias / WSGI_SCRIPT_PATH

<Directory /Users/chrism/modwsgi/env>
  WSGIProcessGroup pyramid
  Order allow,deny
  Allow from all
</Directory>

Whats been bothering us is that the initialize_function gets called on many requests instead of just being called once. We do not understand how apache works or what we have done in the config. We want to be able to call the functions in __init__.py once and thats it. Can someone explain how apache actually works and why pyramid __init__.py is being reloaded all the time. Also explain how we can make sure that the __init__.py is not rerun every request

Consider sharing simple to understand links regarding the same stuff 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T16:12:58+00:00Added an answer on June 18, 2026 at 4:12 pm

    Things like creating a database and prepopulating it shouldn’t go into the __init__.py file of a WSGI application because, as you’ve noticed, this file gets run whenever you start your server (and at certain other points as well).

    What you need is a script which can be called from the command line whenever you need to. Every framework provides their own way to build these. In Pyramid they are called console scripts. Here you can find the documentation of how to build one yourself.

    However, I recommend you use the scaffold (project template) from this tutorial and have a look at the console script called initialize_tutorial_db. It does exactly what you want and allows you to create / initialize your database from the command line whenever you need to.


    Regarding the apache configuration, the line which is relevant to your question is the following:

    WSGIDaemonProcess pyramid user=ubuntu group=staff processes=1 \
       threads=4 \
       python-path= VIRTUAL_ENV_SITE_PACKAGES
    

    It means you will start 1 process with 4 threads. This shouldn’t mean that the code in your __init__.py file is run multiple times. That is more likely to be caused from you restarting the server manually or through code changes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have configured PHP to run under FastCgi on IIS7 on Windows Server 2008
I have a server process that has to execute a lot of database queries,
I have a build server that uses Cruise Control to run our test cases.
I have two MVC3 sites, both hosted on the same server that I've configured
I have a web application that configured to run using IIS , but I
I have a WCF service that is configured to run for a high port
I have a server that runs on Solaris 10, whenever I go to the
I have a server that runs different websites on different ports. All of them
I have a server that is serving files to several windows clients using the
I have a server that returns JSON in the following format: [{Name: Student1, Email:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.