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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:06:52+00:00 2026-06-05T01:06:52+00:00

im using a python script to display text to the screen with ajax but

  • 0

im using a python script to display text to the screen with ajax but it’s laggy and sometimes not even working..

here’s the python script

#!/usr/bin/env python
import cgi, cgitb
form = cgi.FieldStorage()
q = form.getvalue('q')
print "Content-Type: text/html\n" 
print q

and the html

<!DOCTYPE html>
<html>
<head>
    <script type="text/javascript">
        function show(str){
            var xmlhttp;
            if (str.length == 0){
                document.getElementById("hint").innerHTML = "";
                return;
            }
            if(window.XMLHttpRequest){
                xmlhttp=new XMLHttpRequest();
            }
            else{
                xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
            xmlhttp.onreadystatechange=function(){
                if (xmlhttp.readyState==4 && xmlhttp.status==200){
                    document.getElementById("hint").innerHTML=xmlhttp.responseText;
                }
            }
            xmlhttp.open("GET","../cgi-bin/ajax_test.py?q="+str,true);
            xmlhttp.send();
        }
    </script>
</head>
<body>
    <form action="">
        <input type="text" id="txt1" onkeyup="show(this.value)" />
    </form>
    <span id="hint"></span>
</body>

is it my code’s fault? or is it because cgi/python is slow?

  • 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-05T01:06:54+00:00Added an answer on June 5, 2026 at 1:06 am

    While your example works just fine for me on a local OSX apache server, I would suggest that using python CGI as a backend solution to serving ajax calls would be highly inefficient. The very nature of CGI means that every single request has to spawn a process of that python script.

    http://en.wikipedia.org/wiki/Common_Gateway_Interface

    Calling a command generally means the invocation of a newly created
    process on the server. Starting the process can consume much more time
    and memory than the actual work of generating the output, especially
    when the program still needs to be interpreted or compiled. If the
    command is called often, the resulting workload can quickly overwhelm
    the web server.
    The overhead involved in interpretation may be reduced
    by using compiled CGI programs, such as those in C/C++, rather than
    using Perl or other scripting languages. The overhead involved in
    process creation can be reduced by solutions such as FastCGI, or by
    running the application code entirely within the web server using
    extension modules such as mod_php.

    While it may function just fine locally, with just you doing tests, it will be much more impacted when you make it public facing, with multiple clients connecting.

    wsgi (or at least fastcgi) is a far superior approach to old school CGI scripts. You could use mod_wsgi if you are using apache. There is also uwsgi, gunicorn, and many other approaches I am sure. Ultimately the idea is that instead of having a stand alone script that is called for every request, you have a persistant process that is running, accepting requests, and executing functions.

    These days I think people just use the python CGI module as a learning step to writing server-side web code via python. You may want to consider moving over to a framework.

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

Sidebar

Related Questions

I wrote a simple script using python-daemon which prints to sys.stdout : #!/usr/bin/env python
I had the tskill operation working fine through a python script when using Python
I am trying to run a python script using :- python scriptname.py someoptions When
I want to search for images using a Python script and pull them off
I have a batch file containing a python script using the Output template> %(NAME)s
I'm already recording from my iSight from a python script using the pyobjc bridge
I'm trying to run an Icecast stream using a simple Python script to pick
I've got an error when I'm using passthru() to call a python script (using
Background I would like my Python script to pause before exiting using something similar
Suppose I have a python script called my_parallel_script.py that involves using multiprocessing to parallelize

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.