I'm still trying to understand the behaviour that I'm
seeing but I'm already pretty sure that it's either
a bug, or something that would be considered a bug if
it didn't perhaps avoid even worse behaviour.
Inside the join() method of threading.Thread objects,
a Condition named self.__block is acquired, and then
the wait logic is executed. After the wait() finishes,
self.__block is released and the method returns.
If you hit Ctrl-C while the join's wait() is occurring,
you'll raise a KeyboardInterrupt and bypass the
release() call. (I'm observing this on Win XP with
Python 2.4 but have no reason to think it wouldn't
work the same on other platforms, given the docs
on signals and such.) If you do this, the thread
you were waiting for will never be able to complete
its cleanup because __bootstrap() calls __stop()
and that tries to acquire the same Condition object,
which has never been released. (I suspect this will
happen only if its the MainThread that is doing
the join() call since KeyboardInterrupts only occur
in the main thread.)
A simple try/finally in join() appears to solve the
problem, but I'm unsure that this is a good idea,
partly because I'm a little surprised nobody else has
found this problem before and I lack confidence that
I've really found a bug.
Anyone have thoughts on this? I'll file a bug
report shortly unless someone can point out the
error in my reasoning or a reason why this must be
the way it is.
-Peter 3 3193
[Peter Hansen] I'm still trying to understand the behaviour that I'm seeing but I'm already pretty sure that it's either a bug, or something that would be considered a bug if it didn't perhaps avoid even worse behaviour.
Inside the join() method of threading.Thread objects, a Condition named self.__block is acquired, and then the wait logic is executed. After the wait() finishes, self.__block is released and the method returns.
If you hit Ctrl-C while the join's wait() is occurring, you'll raise a KeyboardInterrupt and bypass the release() call.
(I'm observing this on Win XP with Python 2.4 but have no reason to think it wouldn't work the same on other platforms, given the docs on signals and such.)
Then you're doing something other than what you described. Here on
WinXP SP2 w/ Python 2.4c2: import threading class T(threading.Thread):
.... def run(self):
.... import time
.... while True:
.... time.sleep(1)
.... t =T() t.start() t.join()
I can hit Ctrl+C all day at this point, and nothing (visible) happens.
That's because it's sitting in self.__block.wait(), which is in turn
sitting in waiter.acquire(), and it's simply not possible for Ctrl+C
to interrupt a mutex acquire.
If you do this, the thread you were waiting for will never be able to complete its cleanup because __bootstrap() calls __stop() and that tries to acquire the same Condition object, which has never been released. (I suspect this will happen only if its the MainThread that is doing the join() call since KeyboardInterrupts only occur in the main thread.)
A simple try/finally in join() appears to solve the problem, but I'm unsure that this is a good idea, partly because I'm a little surprised nobody else has found this problem before and I lack confidence that I've really found a bug.
Anyone have thoughts on this?
As above, I don't know what you're doing. Maybe you're doing a join()
with a timeout too? In that case, I doubt anyone gave any thought to
what happens if you muck with KeyboardInterrupt too.
Tim Peters wrote: [Peter Hansen]If you hit Ctrl-C while the join's wait() is occurring, you'll raise a KeyboardInterrupt and bypass the release() call.
Then you're doing something other than what you described. Here on WinXP SP2 w/ Python 2.4c2:
[snip] I can hit Ctrl+C all day at this point, and nothing (visible) happens. That's because it's sitting in self.__block.wait(), which is in turn sitting in waiter.acquire(), and it's simply not possible for Ctrl+C to interrupt a mutex acquire.
As above, I don't know what you're doing. Maybe you're doing a join() with a timeout too? In that case, I doubt anyone gave any thought to what happens if you muck with KeyboardInterrupt too.
Yes, definitely doing this with a timeout value on the join().
Changing your example to do that (join(5), say) pretty
much demonstrates the trouble... in this case a traceback
for KeyboardInterrupt is printed, but the program does not
terminate because of the thread stuck at the __stop()'s
__acquire().
I'll take your last sentence as a form of blessing to go
file a bug report, unless you don't think that's a good idea.
Thanks, Tim!
-Peter
Peter Hansen wrote: I'll take your last sentence as a form of blessing to go file a bug report...
Filed as http://sourceforge.net/tracker/index...70&atid=105470
I guess it makes more sense for any further discussion to
go on there...
(Coincidentally, another bug report was filed just a few days
ago for a closely related item. As Tim mentioned, the wait()
without a timeout can never be interrupted by Ctrl-C, and
somebody else reported that as a bug (1167930) only about three
days before I encountered this one.)
-Peter This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
by: ron |
last post by:
If I use the System.Threading.ThreadPool.QueueUserWorkItem to spawn a new
threaded process, will this process be executed regardless of whether or not
the current process ends prior to completion...
|
by: Mark Rae |
last post by:
Hi,
My R&D department has asked me to look at threading in a Web Service written
in C#, so I came up with the following code:
using System;
using System.ComponentModel;
using...
|
by: Elliot Rodriguez |
last post by:
Hi:
I am writing a WinForm app that contains a DataGrid control and a StatusBar
control. My goal is to update the status bar using events from a separate
class, as well as some other simple...
|
by: MattB |
last post by:
Hello
I am starting a new thread in a button click event.
This thread calls an method which sends emails, I don't want the page
to wait for the emails to finish going out as it slows the user...
|
by: AdrianJMartin |
last post by:
Hi all,
I have a need for a STA thread from asp.net. I can create the thread and it
runs fine. But when it is finished, the thread still 'hangs' arround.
Visible only to the debugger.....
I get...
|
by: akrapus |
last post by:
Hi,
I am trying to understand how to use threading in Python. I get
threading as a concept, but not the implementation.
In order to start threading, do you call it as a separate function,...
|
by: Daniel |
last post by:
I have a class similar to this:
class MyThread(threading.Thread):
def __init__(self):
self.terminated = False
def run(self):
while not self.terminated:
|
by: Edwin.Madari |
last post by:
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...
|
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...
|
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: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
| |