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 8294177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:06:44+00:00 2026-06-08T14:06:44+00:00

I have some python code that may result in a division by 0, but

  • 0

I have some python code that may result in a division by 0, but it runs correctly in a python (3.2) interpreter. However, if I try to run it using mod_wsgi, it simply hangs without an error and the request is not served.

Warning in interpreter (output is correct): pathwayAnalysis.py:30: RuntimeWarning: divide by zero encountered in double_scalars

Does anybody know what the correct way to run this using mod_wsgi would be?

The code is below. Both difference and size are numpy float arrays of length 2. Either float in difference may be 0 (but not both). Adding difference += 0.0001 before this makes it run correctly, but is not a nice solution since the output is not accurate:

if abs(difference[0] / difference[1]) > (size[0] / size[1]):
    ratio = abs(size[0] / difference[0])
else: ratio = abs(size[1] / difference[1])
for i in range(len(base)):
    result.append(base[i] + difference[i] * ratio/2)
return array(result)

Doing the following does not work:

try:
    cond = abs(difference[0] / difference[1]) > (size[0] / size[1])
except RuntimeWarning:
    cond = True
# hangs before this point
if cond:
    '''as above'''

Some test code (using either one of the difference definitions):

def application(environ, start_response):
    from numpy import array

    size = array([10., 10.])

    difference = array([115., 0.]) # hangs
    difference = array([115., 10.]) # returns page with text 'Yes.'

    if abs(difference[0]/difference[1]) > (size[0]/size[1]):
        output = 'Yes.'
    else:
        output = 'No.'

    status = '200 OK'

    response_headers = [('Content-type', 'text/plain'),\
        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)

    return [output]
  • 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-08T14:06:46+00:00Added an answer on June 8, 2026 at 2:06 pm

    Some third party packages for Python which use C extension modules, and this includes numpy, will only work in the Python main interpreter and cannot be used in sub interpreters as mod_wsgi by default uses. The result can be thread deadlock, incorrect behaviour or processes crashes. These is detailed in:

    http://code.google.com/p/modwsgi/wiki/ApplicationIssues#Python_Simplified_GIL_State_API

    The workaround is to force the WSGI application to run in the main interpreter of the process using:

    WSGIApplicationGroup %{GLOBAL}
    

    If running multiple WSGI applications on same server, you would want to start investigating using daemon mode because some frameworks don’t allow multiple instances to run in same interpreter. This is the case with Django. Thus use daemon mode so each is in its own process and force each to run in main interpreter of their respective daemon mode process groups.

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

Sidebar

Related Questions

I have some python code that I wrote to convert a python list into
I have some python code that currently performs expensive computation by performing the computation
I have some code in a python string that contains extraneous empty lines. I
I have a python ndarray temp in some code I'm reading that suffers this:
I'm using Django/Python, but pseudo-code is definitely acceptable here. Working with some models that
Let's say I have some isolated Python code that processes data produced by some
I have some Python code with error handling in place but for some reason
I have some python code using shutil.copyfile: import os import shutil src='C:\Documents and Settings\user\Desktop\FilesPy'
I have created some python code which creates an object in a loop, and
I have some really nice Python code to do what I need to do.

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.