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

Aaron Richiger a.richi at bluewin.ch
Wed Aug 29 05:53:40 CEST 2012


Hello Zak!

Nice description and example code! Only a small part of your problem is 
correlated to PySide, most of it is about python in general and django. 
I wrote an example app to show you the possibilities (you only have to 
adapt the path to your django project):
http://pastebin.com/i0MbgMXH

- You figured out already how to start the server using subprocess.

- You wanted the output of the server being printed in a separate 
window(console): This was quite difficult. I am not a Windows user, so 
don't know how to start a console programmatically there, but I suggest 
just using another PySide Widget to show the servers output (see example 
code). Accessing the output was the main problem, due to a bug in django 
(missing sys.stdout.flush() in runserver.py). That's why reading stdout 
seems to be impossible. But only the welcome message is shown in stdout 
and all the rest (info about requests) is printed to stderr with 
flushing, so we can access this. Reading it from subprocess.stderr in a 
loop would be a typical threading task, but there seem to be some 
performance blockers when using PySide (Qt?) with data streams, the GUI 
freezes sometimes when streaming this data directly.
One possible solution is writing the output of the server into a file 
and read the content of this file in a loop. Does not sound too good, I 
know, but the performance is much better, no freezing anymore...

- Getting the closeEvent of both views is no problem, but shutting down 
the django server is not that easy unfortunately. Most of your signals 
would work, if you would send them to the right pid, but knowing this 
pid is difficult, since you only get the one of subprocess.Popen and 
don't know anything about the pids after the process forks to start the 
server. You can hope, that it is pid+1, but this might not always be the 
case. Using some ps-grep-awk etc. magic, you can find the correct pid. I 
did not implement this since it's not PySide related, but it's no 
problem. And then, you can kill this pid.

I hope, this makes sense. Like this, everything is done in one step.
Cheers!
Aaron



More information about the PySide mailing list