Path: csiph.com!eternal-september.org!feeder.eternal-september.org!border1.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'receives': 0.03; '(even': 0.05; 'cpython': 0.05; 'e.g.,': 0.07; 'option,': 0.07; 'socket': 0.07; 'handler,': 0.09; 'portable': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:skip:m 10': 0.09; 'thread': 0.10; 'python': 0.10; 'ctrl+c': 0.16; 'dummy': 0.16; 'needless': 0.16; 'pairs': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'thead': 0.16; 'thread.': 0.16; 'threads': 0.16; 'say,': 0.18; 'windows': 0.20; 'machine': 0.21; 'code,': 0.23; 'seems': 0.23; 'url:bugs': 0.24; 'header:User- Agent:1': 0.26; 'command': 0.26; 'header:X-Complaints-To:1': 0.26; 'handling': 0.27; 'code': 0.30; 'source': 0.33; 'url:python': 0.33; 'message-id:@gmail.com': 0.34; 'handle': 0.34; 'could': 0.35; 'but': 0.36; 'too': 0.36; 'there': 0.36; 'url:org': 0.36; 'possible': 0.36; 'url:library': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'client': 0.37; 'received:org': 0.37; 'seem': 0.37; 'monitor': 0.38; 'test': 0.39; 'subject:-': 0.39; 'to:addr:python.org': 0.40; 'still': 0.40; 'some': 0.40; 'url:3': 0.60; 'behavior': 0.61; 'between': 0.65; 'note:': 0.66; 'present.': 0.72; 'received:89': 0.80; 'demonstrates': 0.84; 'subject:down': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Akira Li <4kir4.1i@gmail.com> Subject: Re: Shutting down a cross-platform multithreaded app Date: Sat, 19 Sep 2015 02:56:17 +0300 References: Mime-Version: 1.0 Content-Type: text/plain X-Gmane-NNTP-Posting-Host: 89.169.229.68 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) Cancel-Lock: sha1:mF6TF/A8ot5tkUqLwv2z5y0s+Rs= X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 44 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1442620567 news.xs4all.nl 23726 [2001:888:2000:d::a6]:37207 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:96842 "James Harris" writes: ... > Needless to say, on a test Windows machine AF_UNIX is not present. The > only cross-platform option, therefore, seems to be to use each > subthread's select()s to monitor two AF_INET sockets: the one to the > client and a control one from the master thread. I would seem to need > IP socket pairs between the master thread and the subthreads. If the > master thead receives a shutdown signal it will send a shutdown > command to each subthread. There is socket.socketpair() on Windows too (since Python 3.5) https://docs.python.org/3/library/socket.html#socket.socketpair http://bugs.python.org/issue18643 Note: you could use select() to handle signals in the main thread too (even on Windows since Python 3.5) if you use signal.set_wakeup_fd() https://docs.python.org/3/library/signal.html#signal.set_wakeup_fd It is known as a self-pipe trick http://www.sitepoint.com/the-self-pipe-trick-explained/ Look at *asyncio* source code, to see how to get a portable implementation for various issues with signals. Some issues might still be opened e.g., Ctrl+C behavior http://bugs.python.org/issue24080 Here's how to combine SIGCHLD signal handling with tkinter's event loop http://stackoverflow.com/questions/30087506/event-driven-system-call-in-python SIGCHLD, createfilehandler() are not portable but the code demonstrates possible set_wakeup_fd() issues and their solutions (O_NONBLOCK, dummy signal handler, SA_RESTART, signal coalescing). On threads and signals in CPython http://bugs.python.org/issue5315#msg102829