Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #68771 > unrolled thread
| Started by | Dave Angel <davea@davea.name> |
|---|---|
| First post | 2014-03-22 09:18 -0400 |
| Last post | 2014-03-22 09:18 -0400 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re:terminate a program gracefully from a thread Dave Angel <davea@davea.name> - 2014-03-22 09:18 -0400
| From | Dave Angel <davea@davea.name> |
|---|---|
| Date | 2014-03-22 09:18 -0400 |
| Subject | Re:terminate a program gracefully from a thread |
| Message-ID | <mailman.8396.1395494060.18130.python-list@python.org> |
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 top | Article view | comp.lang.python
csiph-web