Many thanks! I will not perform the detection rely on this way. On Friday, July 20, 2012 2:09:31 PM UTC+8, Graham Dumpleton wrote: > > There isn't really a way. You can read past discussions on this in the > group archives about points where closure may be detected. One such > discussion is: > > https://groups.google.com/d/msg/modwsgi/jr2ayp0xesk/QtINxMi_KUAJ > > Graham > > On 19 July 2012 22:55, lvqier wrote: > > I am confused with the following code (test.py), which is a wsgi > > application: > > > >> #!/usr/bin/env python > >> > >> from subprocess import Popen, PIPE > >> import os > >> > >> cwd = os.path.dirname(os.path.abspath(__file__)) > >> exe = os.path.join(cwd, 'wait.py') > >> > >> def application(environ, start_response): > >> process_args = ['python', exe, cwd, '100000'] > >> process = Popen(process_args, stdout = PIPE, stderr = PIPE) > >> process.wait() > >> start_response('200 OK', [('Content-Type', 'text/plain'),]) > >> return ['finished'] > > > > > > where wait.py is: > > > >> #!/usr/bin/env python > >> > >> import pyinotify > >> > >> class iNotifyEventHandler(pyinotify.ProcessEvent): > >> def process_IN_CLOSE_WRITE(self, event): > >> fp = event.pathname > >> print 'File created: %s' % fp > >> > >> def watch(folder): > >> watch_manager = pyinotify.WatchManager() > >> watch_manager.add_watch(folder, > >> pyinotify.EventsCodes.ALL_FLAGS['IN_CLOSE_WRITE'], rec = True, auto_add > = > >> True) > >> handler = iNotifyEventHandler() > >> watch_inotify_inst = pyinotify.Notifier(watch_manager, handler) > >> return watch_inotify_inst > >> > >> if __name__ == '__main__': > >> import sys > >> if len(sys.argv) != 3: > >> print 'Usage: %s folder timeout' % sys.argv[0] > >> exit(1) > >> folder = sys.argv[1] > >> timeout = int(sys.argv[2]) > >> notifier = watch(folder) > >> notifier.process_events() > >> if notifier.check_events(timeout = timeout): > >> notifier.read_events() > >> notifier.process_events() > >> > > > > There comes the problem: > > > > When web clients access the wsgi application, the wsgi forks wait.py as > > subprocess and wait it to be finished. But when the subprocess takes too > > long to return, the client may go away before the wsgi application > became > > ready to response. In this situation, I want the subprocess to be > terminated > > as soon as the client is missing. What should I do? > > > > If the wsgi application could catch a signal when the client is gone > away, a > > signal could be sent to the subprocess indicating termination. But I > have no > > idea which signal to be handled in the wsgi application. > > > > Appreciate for your help. > > > > -- > > You received this message because you are subscribed to the Google > Groups > > "modwsgi" group. > > To view this discussion on the web visit > > https://groups.google.com/d/msg/modwsgi/-/ZE5FKEa3d0kJ. > > To post to this group, send email to [email protected]. > > To unsubscribe from this group, send email to > > [email protected]. > > For more options, visit this group at > > http://groups.google.com/group/modwsgi?hl=en. >
-- You received this message because you are subscribed to the Google Groups "modwsgi" group. To view this discussion on the web visit https://groups.google.com/d/msg/modwsgi/-/ofabizUdGZEJ. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/modwsgi?hl=en.
