[PySide] PySide plus Django: How can I make the PySide application auto-start the server?

Zak pyside at m.allo.ws
Wed Aug 29 00:18:11 CEST 2012


Dear PySide People,

I figured out how to make the start-up process one step. I put the 
following in pts_qt.py, right before app.exec_():

# Goes at top, of course:
import subprocess

# Stuff

server = subprocess.Popen(["python", "C:\\Users\\me\\pts\\manage.py", 
"runserver"])

app.exec_()

# If execution reaches this point, it means the Qt GUI window was closed

server.kill()

Now I can start the Qt GUI and the Django server by just double-clicking 
pts_qt.py. Unfortunately, closing the Qt GUI window does NOT stop the 
Django server, even though I called server.kill().

At the moment, it is necessary to close the Qt GUI window and then close 
the Python terminal window, so shutting down the application is now two 
steps. Any idea how I can make it into just one step?

Doesn't work:

server.kill()
server.terminate()
server.send_signal(signal.SIGINT)
# Other signals that don't work:
SIGTERM
1
2
CTRL_C_EVENT
CTRL_BREAK_EVENT

Also doesn't work:

Calling a Django viewfunction that calls sys.exit(). Unfortunately, the 
entire Django server is running inside a "try" clause that looks for and 
disables sys.exit(). I don't want to modify the Django internals, 
although I could and that would work. It would just make installation 
harder, I don't want to do it.

Thanks,

Zak

On 8/28/12 3:29 PM, Zak wrote:
> Dear PySide People,
>
> I am making a PySide application for Windows 7. One important portion 
> of my application is a Django web app. Currently, to start my 
> application, you do the following:
>
> # First, we need to start the Django web server.
>
> 1. Open a terminal ("Command Prompt" on Windows).
>
> 2. At the terminal:
>
> cd /path/to/server/
>
> python manage.py runserver
>
> # Now the server is running.
>
> # Next, we need to start the PySide GUI.
>
> 3. Double-click the file pts_qt.py
>
> # The contents of the file pts_qt.py are attached to this email.
>
> # pts_qt.py is very simple (for the purposes of asking this question), 
> it just opens a Qt GUI window, fills it with a QWebKit browser, and 
> points the browser at http://127.0.0.1:8000/, which is the URL of the 
> website being served by Django.
>
> As you can see, starting my application requires 3 steps. I want it to 
> be just one step. That step should be "Double-click the file 
> pts_qt.py", and that should start the Django webserver automatically.
>
> It would also be nice if closing the Qt GUI by clicking the "X" in the 
> corner of the window would stop the Django server too.
>
> How can I make pts_qt.py start the Django server automatically? Note 
> that the Django server should start its own terminal window (Command 
> Prompt window) which prints status messages and stuff.
>
> Thank you,
>
> Zak
>
> P.S. You might be asking, "Why is this a PySide app and not just a web 
> app?" Well, the actual application is more complicated. It comes in 
> three flavors:
>
> A. Pure Web App, to be used remotely and with nothing but a browser.
>
> B. Remote Thick Client. This is a PySide app that interacts with the 
> remote web server, but also does special non-web stuff, like 
> interfacing with hardware.
>
> C. Pure Local Client. This is a PySide app that is like the Remote 
> Thick Client, except that it doesn't connect to the mothership server. 
> It starts its own Django server. This is the thing we are trying to fix.




More information about the PySide mailing list