Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #68771
| Path | csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.002 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'below)': 0.09; 'caching,': 0.09; 'cleanup': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'suppress': 0.09; 'gui': 0.12; 'wrote': 0.14; 'thread': 0.14; 'abort': 0.16; 'blocking': 0.16; 'caching': 0.16; 'displaying': 0.16; 'graceful.': 0.16; 'idea:': 0.16; 'invocation': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'seconds.': 0.16; 'simplified': 0.16; 'subject:program': 0.16; 'thread,': 0.16; 'threads.': 0.16; 'version.': 0.19; 'starts': 0.20; 'load': 0.23; 'script': 0.25; '(see': 0.26; 'header:X-Complaints-To:1': 0.27; 'idea': 0.28; 'code': 0.31; 'terminate': 0.31; 'figure': 0.32; 'quite': 0.32; 'maybe': 0.34; 'subject:from': 0.34; 'could': 0.34; "can't": 0.35; 'but': 0.35; 'minutes,': 0.36; 'done': 0.36; 'doing': 0.36; 'next': 0.36; 'hi,': 0.36; 'should': 0.36; 'seconds': 0.37; 'starting': 0.37; 'to:addr:python-list': 0.38; 'does': 0.39; 'launch': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'received:org': 0.40; 'how': 0.40; 'read': 0.60; 'signal': 0.60; 'simple': 0.61; 'first': 0.61; 'real': 0.63; '3-4': 0.68; 'launch.': 0.84; 'quicker': 0.84; 'subject::': 0.85 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Dave Angel <davea@davea.name> |
| Subject | Re:terminate a program gracefully from a thread |
| Date | Sat, 22 Mar 2014 09:18:52 -0400 (EDT) |
| Organization | news.gmane.org |
| References | <CAOuJsMny-DV2kLS2EU1=FtHr6zkMH__-Q-2z8_-wnaSKmap8iA@mail.gmail.com> |
| X-Gmane-NNTP-Posting-Host | dpc6744198232.direcpc.com |
| X-Newsreader | PiaoHong Usenet NewsReaders 1.36 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.8396.1395494060.18130.python-list@python.org> (permalink) |
| Lines | 38 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1395494060 news.xs4all.nl 2867 [2001:888:2000:d::a6]:51933 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:68771 |
Show key headers only | View raw
Jabba Laci <jabba.laci@gmail.com> Wrote in message: > Hi, > > I have a script (see below) that I want to terminate after X seconds. > The main loop of the program is waiting for user input. > The program enters the main loop and I try to shut down the program > after X seconds from a thread but I can't figure out how to do it. The > program should also do some cleanup before termination, so the shut > down must be graceful. > > The code below is a simplified version. The whole idea is the > following: I have a script that has grown quite big over time. It > needs to read several data files, so when I start it for the first > time, it takes about 3-4 seconds to launch. The next start is much > faster since, I guess, the OS has done some caching. I use this script > a lot and the first slow launch bothers me. My idea: after booting, I > want to start the script in the background in suicide mode. OS does > the caching, so when I need it, it starts quickly. > You need a flag to indicate that a particular invocation is the dummy one (background). So use that same flag either to suppress starting the thread, or to avoid the unwanted raw_input. If you had no blocking I/o, you could use a simple global to notify all the threads. Or use a signal to abort the main thread if it's stuck in raw_input. Alternatively, rethink the need to preload at boot time. Any caching the OS does is likely to only last a few minutes, depending on load. So maybe you can make the real load seem to be quicker by displaying the gui right away, but doing the time-consuming part in a thread. -- DaveA
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re:terminate a program gracefully from a thread Dave Angel <davea@davea.name> - 2014-03-22 09:18 -0400
csiph-web