I have a problem which I am hoping might be solved with some form of shutdown hook in Django.
I am still a beginner with Python/Django development, and to help learn I have set myself a project of developing a COMET/Reverse Ajax style chat site that runs in browser. The browser continuously polls the server for any messages. When the server receives a poll request, it checks to see if there are any messages waiting, and if there are none, it will attempt to acquire a lock on a threading.Lock object which has already been acquired. This causes the thread which is handling the request to block until a message is received and the previously mentioned lock is released.
My problem arises when I shutdown the server. At this point I am using the development server (python manage.py runserver). If there is a thread blocked from the above explained process, then the server does not shutdown.
Is there a way that i can execute code when the server attempts to shutdown so that i can release any waiting threads?
I have looked at the following similar question however it hasn't helped me. There was speculation that such an event hook does not exist, however no definitive answer. I've googled high and low, but haven't had any luck.
I am using Python 2.7 and Django 1.5.
Grateful for any help you can provide
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…