Zoip
Zoip

Reputation: 61

python-fastcgi extension

There's not much documentation surrounding the python-fastcgi C library, so I'm wondering if someone could provide a simple example on how to make a simple FastCGI server with it. A "Hello World" example would be great.

Upvotes: 3

Views: 2434

Answers (2)

Mike Boers
Mike Boers

Reputation: 6735

I would recommend using a fastcgi WSGI wrapper such as this one, so you aren't tied in to the fastcgi approach from the start.

And then a simple test.fgi file like such:

#!/usr/bin/env python

from fcgi import WSGIServer

def app(env, start):

    start('200 OK', [('Content-Type', 'text/plain')])
    yield 'Hello, World!\n'
    yield '\n'

    yield 'Your environment is:\n'
    for k, v in sorted(env.items()):
        yield '\t%s: %r\n' % (k, v)

WSGIServer(app).run()

Upvotes: 3

a paid nerd
a paid nerd

Reputation: 31512

Edit: I misread the question. Ooops.

Jon's Python modules is a collection of useful modules and includes a great FastCGI module: http://jonpy.sourceforge.net/fcgi.html

Here's the example from the page:

import jon.cgi as cgi 
import jon.fcgi as fcgi

class Handler(cgi.Handler):
  def process(self, req):
    req.set_header("Content-Type", "text/plain")
    req.write("Hello, world!\n")

fcgi.Server({fcgi.FCGI_RESPONDER: Handler}).run()

Upvotes: 4

Related Questions