> Den 18/11/2014 kl. 16.50 skrev Arun Marathe <ap.mara...@gmail.com>: > > For a somewhat obscure reason, I need to stop the testserver from within a > test case. Any ideas? > I would like a programmatic solution if possible. Finding a process and > killing it (ps -ef., then grep, > then kill) is bit of a hack, and may end up killing unintended processes.
By "test server" I assume you mean the built-in Django development server. The development server is running in a completely different process from your test case, so your options are somewhat limited. The development server does a really good job of staying alive, so you can't raise KeyboardInterrupt or sys.exit() because the development server will simply restart. I would probably create a special view that you van call from your test case, e.g. GET http://localhost:8000/killme, which finds the process ID of itself (the development server) and signals it to stop. Something like this: class KillMe(View): def get(request): import os import signal pid = os.getpid() os.kill(pid, signal.SIGINT) Depending on your needs, you might need to let your test case wait until the development server process has actually terminated. Erik -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9D100E03-0CD0-4BFB-B2B5-E6CE5B7EE57F%40cederstrand.dk. For more options, visit https://groups.google.com/d/optout.