I'm not quite sure why, but Ctrl-C doesn't really work like it should on my Windows XP
with python web servers.
Ctrl-C doesn't stop appliactions immediately - instead, after
pressing Ctrl-C on console one has to go to web browser,
try to load the page and only after error page is displayed in browser the console
application stops.
I guess this is because select system call is not interruptible in Python. However,
sleep is interruptible, so simple workaround is to run original dev_appserver in
subthread and to sleep() for a long time in never-ending loop in main thread.
This is not the most polite way to end thread - try-except blocks in subthread
do not have change to act on KeyboardInputerrupt exception and cleanly shutdown,
but it does it's job and I haven't really noticed anything bad
happening with my Google App Engine
Development Environment.
Here's little patch you can apply to dev_appserver.py:
--- dev_appserver.py.orig Fri Oct 03 12:28:20 2008
+++ dev_appserver.py Fri Oct 31 22:18:19 2008
@@ -52,4 +52,17 @@
script_name = os.path.basename(__file__)
script_name = SCRIPT_EXCEPTIONS.get(script_name, script_name)
script_path = os.path.join(SCRIPT_DIR, script_name)
- execfile(script_path, globals())
+ def run():
+ execfile(script_path, globals())
+ if sys.platform == 'win32':
+ sys.stdout.write('Running in subthread on Windows.\n');
+ import threading, time
+ t = threading.Thread(target=run)
+ t.setDaemon(True)
+ t.start()
+ try:
+ while True: time.sleep(3600)
+ except KeyboardInterrupt:
+ pass
+ else:
+ run()
You can download it here: dev_appserver_ctrlc_mp.patch, you can also download modified file here: dev_appserver_ctrlc_mp.py (this file is part of Google App Engine software, copyrithted by Google, released as OpenSource, so I guess providing modified file for download is legal - if it's not please let me know).
Of course I can't give you any guarantees that this works or that it wont destroy your app, installation, hardware or anything. Use at your own risk.
$Id: notes-google-app-engine-dev_appserver-patch.html,v 1.4 2009/02/02 22:07:28 maciej Exp $