473,813 Members | 3,529 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

stoppable child thread

I am trying to use Peter's StoppableThread (threading.Thre ad).

What I want to do is to start 5 child threads, then do something, then
when got ^C keyboard exception, stop the child thread.

For some reason (apparently strange for me :) ), the child threads can
NOT be stopped.

See the enclosed code for more info,

Thanks and have a nice Xmas.

Jimmy

============

#!/usr/bin/env python

import threading, thread
from time import sleep, ctime
class StoppableThread (threading.Thre ad):
def __init__(self):
threading.Threa d.__init__(self )
self._running = True
def stop(self):
self._running = False
def run(self):
while self._running:
# do stuff here that loops periodically to allow
# the flag to be checked
print 'start loop at:', ctime()
sleep(4)

def main():
threads = []
try:
for i in range(5):
t = StoppableThread ()
t.start()
sleep(0.001)
threads.append( t)
except KeyboardInterru pt:
for t in threads:
t.stop()
t.join()
del threads[:]
print 'child thread exiting...'+'/n/n'

if __name__ == '__main__':
main()

Dec 22 '06 #1
1 2984
ja*******@yahoo .com ha escrito:
def main():
threads = []
try:
for i in range(5):
t = StoppableThread ()
t.start()
sleep(0.001)
threads.append( t)
except KeyboardInterru pt:
for t in threads:
t.stop()
t.join()
del threads[:]
print 'child thread exiting...'+'/n/n'
Put a print statement just at the end of main() and see what happens.
You said:
What I want to do is to start 5 child threads, then do something, then
when got ^C keyboard exception, stop the child thread.
You've created the threads, you've handled ^C, what's missing...?

--
Gabriel Genellina

Dec 22 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3347
by: jinu | last post by:
Hello, My application loads with a form which is the mdi parent and a menu item click (main menu of the parent form) brings up a child form. I have to wait for a considerable amout of time to execute an oracle procedure which has to be invoked from the above said child form. The problem now is, during this waiting time, my mdi parent's menu is appearing to be not responding (becoming white in simple words). Once the oracle procedure is...
10
2279
by: Barbara Alderton | last post by:
I am working with SharePoint 2003. I am using (using C#) an existing webpart as a child control (server control). I need to access/manipulate the HTML that the control outputs prior to rendering it to the the page. The control outputs a list in a one-column table format. I need to access the contents of the rows and output them with restrictions in my own table format. Does anyone have any examples of manipulating the HTML of a server...
4
2036
by: Bonj | last post by:
Further to my last post, I have managed to get a child window to display. But its messages are routed to the same WNDPROC that the main window's messages are routed to - what is the way of identifying from the lParam or wParam whether the message came from a child window or the parent? And what if the message uses some other data in the wParam or lParam? Is it better to use one wndproc for the parent window, and one wndproc for all child windows...
3
1896
by: Vinicius Bellino | last post by:
Hi All, Is there a way to change a property of an UI control, such as the enabled property of a button, in a child thread? I mean, my code runs a long process, and because I wanted to show the status in another popup window, I created a new (child) thread to run the long process and I let the main thread open a new popup with auto-refresh to show the status, using a shared Session variable to pass the current status between these...
6
4166
by: Dinesh Jain | last post by:
Hi all, How to inform Parent thread from a Child Thread? I mean want to notify something from Child thread to Parent Thread. Please help, Thanks in advance, -Regards, Dinesh
2
2460
by: Chen Houwu | last post by:
------------------sample code begin------------------------- import threading import wmi def run(*args): c = wmi.WMI () memory=c.Win32_LogicalMemoryConfiguration() info='Total Virtual Memory: '\
2
1990
by: sunil | last post by:
Hi All, I am tring to debug the following program.I written this program in HP-Unix and I am using the GDB as a debugger. #include <stdio.h> #include<unistd.h> int main() { int pid; pid = fork();
2
4428
by: =?Utf-8?B?a2VubmV0aG1Abm9zcGFtLm5vc3BhbQ==?= | last post by:
vs2005, c# Trying to understand why one way works but the other doesnt. I have not tried to create a simpler mdi/child/showdialog app for posting purposes (I think even this would not be so small or simple). I am hoping the description will generate some ideas I can check out. PROBLEM: ----------------- Switching to UI thread using Invoke(), everything seems good.
1
1475
by: Vneha | last post by:
Hi class NewThread implements Runnable { Thread t; NewThread() { t = new Thread(this, "Demo Thread"); System.out.println("Child Thread:" + t); t.start(); }
0
9734
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9607
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10667
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10407
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10139
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6897
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5568
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4358
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3885
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.