Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #96838
| References | <mthgrk$uh1$1@dont-email.me> |
|---|---|
| Date | 2015-09-19 07:40 +1000 |
| Subject | Re: Shutting down a cross-platform multithreaded app |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.8.1442612439.21674.python-list@python.org> (permalink) |
On Sat, Sep 19, 2015 at 3:17 AM, James Harris <james.harris.1@gmail.com> wrote: > 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. > > The above seems logical but would use quite a few IP sockets. I cannot think > of a better way, though. Any comments on the ideas above? If you're using select() to monitor the sockets, you don't actually then have to _do_ anything with the shutdown socket. You could have a single socket that sends the shutdown signal to all your workers. Bear in mind, though, that Windows has no protection against other processes shutting you down. You can restrict it to 127.0.0.1 (of course) but any program running on the same computer as the server - regardless of user permissions etc - will be able to connect to your sockets. So it might be best to do something like this (all on the main thread): 1) Open a listening socket 2) Connect to the listening socket 3) Accept a connection 4) Close the original listening socket 5) Spin off all your threads, passing them the socket from step 2 6) To terminate them all, write a byte to the socket from step 3. This will make it difficult for ordinary userspace code to mess with you. It'd still be possible, I think, for something with raw sockets access to feign a termination signal; I have no idea what protections Windows offers you there. Give it a shot, see how it goes! ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Shutting down a cross-platform multithreaded app "James Harris" <james.harris.1@gmail.com> - 2015-09-18 18:17 +0100
Re: Shutting down a cross-platform multithreaded app Paul Rubin <no.email@nospam.invalid> - 2015-09-18 11:23 -0700
Re: Shutting down a cross-platform multithreaded app "James Harris" <james.harris.1@gmail.com> - 2015-09-18 20:09 +0100
Re: Shutting down a cross-platform multithreaded app Laura Creighton <lac@openend.se> - 2015-09-18 22:50 +0200
Re: Shutting down a cross-platform multithreaded app "James Harris" <james.harris.1@gmail.com> - 2015-09-19 10:56 +0100
Re: Shutting down a cross-platform multithreaded app Marko Rauhamaa <marko@pacujo.net> - 2015-09-18 23:40 +0300
Re: Shutting down a cross-platform multithreaded app Chris Angelico <rosuav@gmail.com> - 2015-09-19 07:40 +1000
Re: Shutting down a cross-platform multithreaded app "James Harris" <james.harris.1@gmail.com> - 2015-09-19 10:49 +0100
Re: Shutting down a cross-platform multithreaded app Chris Angelico <rosuav@gmail.com> - 2015-09-19 20:14 +1000
Re: Shutting down a cross-platform multithreaded app "James Harris" <james.harris.1@gmail.com> - 2015-09-19 11:48 +0100
Re: Shutting down a cross-platform multithreaded app Chris Angelico <rosuav@gmail.com> - 2015-09-19 20:59 +1000
Re: Shutting down a cross-platform multithreaded app Random832 <random832@fastmail.com> - 2015-09-18 17:48 -0400
Re: Shutting down a cross-platform multithreaded app Chris Angelico <rosuav@gmail.com> - 2015-09-19 08:09 +1000
Re: Shutting down a cross-platform multithreaded app Akira Li <4kir4.1i@gmail.com> - 2015-09-19 02:56 +0300
csiph-web