0

I have a python server that I need to run in both a Linux and Windows environment, and my question is about deployment. What is the best method for deploying the solution instead of just double clicking on the file and running it?

Since I use the server_forever() on the server, I can just run the script from command line, but this keeps the python window open. If I log off the machine, naturally the process will stop. So what is the best method for deploying a python script that needs to keep running if the user is logged in or off a machine.

Since I am going to be using multiple environment, Linux and Windows, can you please be specific in what OS you are talking about?

For windows, I was thinking of running the script 'At Startup' using the Windows scheduler. But I wanted to see if anyone had a better option. For linux, I really don't know what to create. I am assuming a CRON job?

Deployment does refer to coding, so using serve_forever() on a multiprocessing job manager keeps the python window open upon execution. Is there a way to hide this window through code? Would you recommend using a conversion tool like py2exe instead?

Brent Worden
  • 10,624
  • 7
  • 52
  • 57
code base 5000
  • 3,812
  • 13
  • 44
  • 73
  • On Hold? What is with you people, I have a deployment question and that's not about programming? Not everyone knows everything, and we need help sometimes. Where should this be posted then? – code base 5000 Jul 17 '13 at 10:43

1 Answers1

1

This is the subject matter of a whole library of books, so I will just give an introduction here :-) You can basically start scripts directly and then have multiple options to do this in a way that they keep running in the background.

If you have certain functionality that needs to run on regular moments, you would do this by scheduling it:

  • Windows: Windows Scheduler or specific scheduling tools
  • Linux: Cron

If your problem is that you want to start a script without it closing on you while SSH'ing into Linux, you want to look into the "screen" or "tmux" tools.

If you want to have it started automatically this could be done by using the "At Startup" as you point out and Linux has similar functionalities, but the preferred and more robust way would be to set up a service that is better integrated with the OS.

Even more capabilities can be yielded by using an application server such a Django

Tomcat (see comment) is an option, but definitely not the standard one; you'll have a hard time finding support both from Tomcat people running Python or Python people running their stuff on Tomcat. That being said, I imagine you could enable CGI and have it run a Python command with your script.

Yet, instead of just starting a Python script I would strongly encourage you to have a look at different Python options that are probably available for your specific use case. From lightweight web solutions like Flask over a versatile networking engine like Twisted to a full blown web framework like Django.

They all have rather well-thought-out deployment solutions available. Look up WSGI for more background.

Community
  • 1
  • 1
Dirk
  • 2,348
  • 17
  • 23
  • Can you explain a bit more on using the Django application server? Could tomcat be used instead (apache's application server)? – code base 5000 Jul 16 '13 at 14:11