Dan's solution is good.  Another way to do it purely from within
python would be to fork off a separate process within your python code
(though you'd have to redirect stdout and stderr to log files within
your python file) like this (no promises, haven't run this code):

if __name__ == '__main__':
    import os, sys
    pid = os.fork()
    if pid is 0:
        sys.stdout = open('out.txt', 'w')
        sys.stderr = open('err.txt', 'w')
        app = web.application(...)
        app.run()
    else:
        print "Server forked off with pid of: %d" % pid


Cheers,
Justin

On Sep 15, 11:49 pm, Dan Loewenherz <[email protected]> wrote:
> IMO It's much easier to just run the process with an ampersand and redirect
> log output to a file.
> e.g.
>
> $ python code.py >log.txt 2>&1 &
> [2] 36879
> $
>
> You can end this terminal session and the python process will continue to
> run in the background. View the debug output by opening log.txt. If you want
> to kill this process, just type
>
> $ kill 36879
>
> You may need superuser privileges for kill to work. Screen is a great tool,
> but this isn't really what you should be using it for.
>
> Best,
> Dan
>
> On Tue, Sep 15, 2009 at 6:55 PM, boubou_cs <[email protected]> wrote:
>
> > ow to start webpy command line and exit the terminal without
> > interrupting
> > the program ?
>
> > I found this solution that I wish to share, but I do not know if any
> > other.
>
> > If you work with lighttpd and use it with proxy, webpy behind, it is
> > possible
> > that you need to close the terminal. Unfortunately the closure of the
> > terminal
> > would stop webpy if it is started with "python code.py" command line.
>
> > The command "screen" on Linux allows you to run lengthy processes that
> > normally
> > needs to be started and stopped manually. screen is an easy way to
> > allow
> > processes to continue running after the session is terminated or if
> > you lose
> > connection ( screen will save your spot).
>
> > First, you must run the command by appointing a session:
> >        screen -S project_name
>
> >        exemple :
> >        screen -S webpy-server
>
> > Session webpy-server may be recalled later.
>
> > Now you are running in screen.
> > The new terminal session appears blank. Just type the desired command:
> >        python /home/mylogin/webpy/web/code.py
>
> > This starts the server webpy in the new session.
>
> > If you want to disconnect from this screen and leave your processes
> > running hit
> >        ctrl-a + d
> > You can close too the terminal or connect yourself to that session
> > from a
> > remote terminal (via ssh for exemple).
>
> > If you want to reconnect to the session:
> >        screen -r project_name
>
> > If you can not remember the name of the project or if you want to list
> > all projects :
> >        screen -list
>
> >        Terminal shows for exemple:
> >        13379.toto1 (Detached)
> >        13308.toto2 (Detached)
> >        13356.toto3 (Dead ???)
>
> > If you have dead screen ( as in the example above) you can remove
> > them:
> >        screen -wipe
>
> > I do not know if it is a good solution, but for now the only one I
> > found.
> > Perhaps you know others?
>
> > Best regards,
>
> > Boubou.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/webpy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to