Reputation: 1678
I am creating a webservice in Python and I have a question. I want to separate the user login user data. For this I am creating two different Python programs.
For example: login.py -> localhost: 8080 userData.py -> localhost: 8081
My question is: how I can run these two programs on the same server? Is there a Python application server that is easy to use?
Thank you very much!
Upvotes: 0
Views: 1669
Reputation: 77251
If the webserver is embedded in the application, you may want to use some "watchdog" application to start/stop/restart.
Ubuntu uses upstart.
I like to use supervisord for this as well.
If the application supports some webserver integration protocol like FCGI or WSGI (python's standard), you may want to deploy it using a webserver. I've used apache mod_wsgi for a long time, lately I tend to use nginx+uwsgi. Apache is a fine webserver, but nginx+wsgi scale better.
[update]
Applications use Bottle + PyMongo (MongoDB) What do you recommend to be scalable?
First you should follow the advice on your framework documentation about deployment (bottle is not verbose about this subject, so I understand why you are asking).
B1 comment is right. You definitely want to place the database and application on distinct servers.
For maximum scalability with minimum fuzz you may want to look at some PasS provider like heroku, instructions here. This makes sense specially if you are a developer and not a system administrator.
Upvotes: 1
Reputation: 25569
Tornado is a very easy to use application server. You can listen on different ports with different request handlers.
It is scalable and can handle thousands of connections. We use it to handle our console server. The simple hello world code really tells you all you need to know. I've added another HttpServer so that the single ioloop is handling requests on two different ports :
import tornado.ioloop
import tornado.web
from tornado.httpserver import HttpServer
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.write("Hello, world")
class OtherHandler(tornado.web.RequestHandler):
def get(self):
self.write("Goodbye, world")
application1 = tornado.web.Application([
(r"/", MainHandler),
])
application2 = tornado.web.Application([
(r"/", OtherHandler),
])
if __name__ == "__main__":
HttpServer(application1).listen(8080)
HttpServer(application1).listen(8081)
tornado.ioloop.IOLoop.instance().start()
Upvotes: 0
Reputation: 12069
Since you are on Ubuntu, using bash:
./login.py &
./userData.py &
This will run both scripts in the background.
If you want these scripts to keep on running after you close your shell:
at now < ./login.py
at now < ./userData.py
Upvotes: 0