473,320 Members | 2,189 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

RE: threading

1. check out the Caveats for thread module: http://docs.python.org/lib/module-thread.html

Threads interact strangely with interrupts: the KeyboardInterrupt exceptionwill be received by an arbitrary thread. (When the signal module is available, interrupts always go to the main thread.)

i.e., all threads (including main) to catch interrupt exceptions, and propagate that information to other threads.

2. since there is no way to interrupt a sleep (not aware of any), sleep is not the choice. use something else like napping. I mean, take shorter intervals of sleep, check every thing is fine and go back to napping. if something is fishy - go catch it.

hope that helps.
Edwin
-----Original Message-----
From: py************************************************ **@python.org
[mailto:py***************************************** *********@python.org]
On Behalf Of Rhamphoryncus
Sent: Thursday, August 14, 2008 2:52 PM
To: py*********@python.org
Subject: Re: threading
On Aug 14, 3:30*am, "Mathieu Prevot" <mathieu.pre...@ens.frwrote:
2008/8/13 Parimala <parimal...@accord-soft.com>:
Hello,
* * * *I am using python2.5.1 version to run my test scripts. Iwant to use
'threading' module in my tests. As a startup program, I had run the
following one.
importthreading
import sys
import time
def hello():
* i=0
* try:
* * while i<10:
* * * print "hi"
* * * time.sleep(1)
* * * i+=1
* except KeyboardInterrupt:
* * print 'KeyboardInterrupt'
* * raise KeyboardInterrupt
try:
* thread=threading.Thread(target=hello,args=())
* thread.start()
except KeyboardInterrupt:
* print 'KeyboardInterrupt'
* raise KeyboardInterrupt
once program starts, problem is..
I am not able to abort the thread using (CTRL+C) KeyboardInterrupt. *While
running if I press CTRL+C, it won't generate any exception until the end of
the execution. Once the execution gets over, *it will give "Exception
exceptions.KeyboardInterrupt in <module 'threading' from
'C:\python25\lib\threading.py'ignored" this message and exits.
I had gone through some documents, it says if a thread is joined with
.join() method then we can't stop that process until it releases the lock
what it acquired. But in the above program I didn't use .join() method but
still I am not able to abort the thread.
Could you please suggest me how can I abort the thread at any point in time
using CTRL+C.

Hi,

a terminate method is given here:http://sebulba.wikispaces.com/recipe+thread2

so you can terminate the thread by:

(...)
t.start()
(...)

while True:
* try:
* * #some code
* except KeyboardInterrupt:
* * t.terminate()
* * break

Mathieu
(For some reason the OP hasn't come through to groups.google.com..
odd)

Note that it won't interrupt any blocked I/O, which is often what you
need the most. If your threads are CPU-bound you can simply have them
check a flag and exit if it becomes True.
--
http://mail.python.org/mailman/listinfo/python-list
The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure. If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof. Thank you.
Aug 14 '08 #1
0 1204

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

Similar topics

65
by: Anthony_Barker | last post by:
I have been reading a book about the evolution of the Basic programming language. The author states that Basic - particularly Microsoft's version is full of compromises which crept in along the...
2
by: Egor Bolonev | last post by:
hi all my program terminates with error i dont know why it tells 'TypeError: run() takes exactly 1 argument (10 given)' =program==================== import os, os.path, threading, sys def...
77
by: Jon Skeet [C# MVP] | last post by:
Please excuse the cross-post - I'm pretty sure I've had interest in the article on all the groups this is posted to. I've finally managed to finish my article on multi-threading - at least for...
6
by: CK | last post by:
I have the following code in a windows service, when I start the windows service process1 and process2 work fine , but final process (3) doesnt get called. i stop and restart the windows service...
2
by: Vjay77 | last post by:
In this code: Private Sub downloadBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) If Not (Me.downloadUrlTextBox.Text = "") Then Me.outputGroupBox.Enabled = True...
11
by: Paul Sijben | last post by:
I am stumped by the following problem. I have a large multi-threaded server accepting communications on one UDP port (chosen for its supposed speed). I have been profiling the code and found...
17
by: OlafMeding | last post by:
Below are 2 files that isolate the problem. Note, both programs hang (stop responding) with hyper-threading turned on (a BIOS setting), but work as expected with hyper-threading turned off. ...
0
by: kingcrowbar.list | last post by:
Hello Everyone I have been playing a little with pyGTK and threading to come up with simple alert dialog which plays a sound in the background. The need for threading came when in the first...
7
by: Mike P | last post by:
I am trying to write my first program using threading..basically I am moving messages from an Outlook inbox and want to show the user where the process is up to without having to wait until it has...
126
by: Dann Corbit | last post by:
Rather than create a new way of doing things: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2497.html why not just pick up ACE into the existing standard:...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.