2

I'm a green hand in Python.I have got a simple webservice with python as following:

enter code here

import soaplib
from soaplib.core.service import rpc, DefinitionBase
from soaplib.core.model.primitive import String, Integer
from soaplib.core.server import wsgi
from soaplib.core.model.clazz import Array
from soaplib.core.service import soap

class HelloWorldService(DefinitionBase):

    @soap(String,Integer,_returns=Array(String))
    def say_hello(self,name,times):
        results = []
        for i in range(0,times):
            results.append('Hello, %s'%name)
        return results
if __name__=='__main__':

    try:

        from wsgiref.simple_server import make_server
        soap_application = soaplib.core.Application([HelloWorldService], 'tns')
        wsgi_application = wsgi.Application(soap_application)
        server = make_server('10.44.138.231', 9999, wsgi_application)
        server.serve_forever()

    except ImportError:

        print "Error: example server code requires Python >= 2.5"

it's very fast when I access the service in localhost,but it will become very slow from the another host in local area network.

so I want to deploy this program in apache,but it seems hard,I search this in google for a long time and it makes me very tired now. who can give me a help,Thank you

1
  • 1
    This might help. Commented Jun 27, 2012 at 7:36

2 Answers 2

1

I would recommend using mod_wsgi (rather than mod_python), as WSGI is the standard way to host Python web applications.

You need to have a function called application in the global scope, in your case:

        # ....
        return results

soap_application = soaplib.core.Application([HelloWorldService], 'tns')
application = wsgi.Application(soap_application)

if __name__ == "__main__":
    # ....

You then enable mod_wsgi in Apache and add directives in (WSGIScriptAlias is the main one). The help pages are reasonably accessable if you've configured Apache before.

Sign up to request clarification or add additional context in comments.

Comments

0

As your webservice uses WSGI to serve the files, you can use any WSGI-compliant Apache module, e.g. mod_wsgi.

You can also use a standalone WSGI server like Gunicorn and then pass on the requests from your primary web server to the Gunicorn server process.

In case you're not required to use Apache: Nginx combined with Gunicorn or uwsgi is a very widely used solution to serve WSGI apps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.