473,883 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Re: Thread killing - I know I know!

sj*******@yahoo .com wrote:
On May 16, 11:40 am, Roger Heathcote <use...@technic albloke.com>
wrote:<snip>
>Despite many peoples insistence that allowing for the arbitrary killing
of threads is a cardinal sin and although I have no particular threading
problem to crack right now I remain interest in the taboo that is thread
killing. The real world and it's data are messy and imperfect and I can
<snip>
In general, use processes when you can and threads only when you
must. OS designers spent a lot of energy implementing protected
memory, no sense throwing out a fair chunk of that hard work unless
you actually need to.
Fair point, but for sub processes that need to be in close contact with
the original app, or very small functions that you'd like 100s or 1000s
of it seems like a kludge having to spawn whole new processes build in
socket communications and kill via explicit OS calls. I can't see that
approach scaling particularly well but I guess there's no choice.

Does anyone think it likely that the threading module (and threading in
general) will be improved and augmented with features like timeouts and
arbitrary threadicide in the next year or two? Seems there's little
scope for tapping the power of the current generation of multiple cores
with the current pythons, tho I appreciate breakneck speed has never
been a design objective it looks like multicore is set to be the next
generation PC architecture.

Roger Heathcote - technicalbloke. com
Jun 27 '08 #1
6 1913
On Mon, May 19, 2008 at 11:36 AM, Roger Heathcote
<us****@technic albloke.comwrot e:
sj*******@yahoo .com wrote:
>>
On May 16, 11:40 am, Roger Heathcote <use...@technic albloke.com>
wrote:<snip>
>>>
Despite many peoples insistence that allowing for the arbitrary killing
of threads is a cardinal sin and although I have no particular threading
problem to crack right now I remain interest in the taboo that is thread
killing. The real world and it's data are messy and imperfect and I can

<snip>
>>
In general, use processes when you can and threads only when you
must. OS designers spent a lot of energy implementing protected
memory, no sense throwing out a fair chunk of that hard work unless
you actually need to.

Fair point, but for sub processes that need to be in close contact with the
original app, or very small functions that you'd like 100s or 1000s of it
seems like a kludge having to spawn whole new processes build in socket
communications and kill via explicit OS calls. I can't see that approach
scaling particularly well but I guess there's no choice.
It's not a kludge - the whole reason why killing a thread is undefined
and a "cardinal sin" is because it's in your own address space and you
can't guarantee anything about how it left things when you killed it.
You simply can't have it both ways. If you want to be able to safely
and sanely kill an uncooperative thread (*especially* third party code
you don't control) you have to isolate it from your address space, and
this means a process. This is a fundamental problem with the entire
idea of shared-state concurrency. For the record, you can't use 1000s
of threads either - if you really need 1000s of concurrent things
running you need to re-think your concurrency model and possibly your
choice of languages and environment.

The messiness of the real world is *why* you should use processes, not
a reason to avoid them.
Does anyone think it likely that the threading module (and threading in
general) will be improved and augmented with features like timeouts and
arbitrary threadicide in the next year or two? Seems there's little scope
for tapping the power of the current generation of multiple cores with the
current pythons, tho I appreciate breakneck speed has never been a design
objective it looks like multicore is set to be the next generation PC
architecture.
They absolutely should not be. Adding an API which can't work in the
general case and is dangerous even when it can work does not do anyone
any favors.
Roger Heathcote - technicalbloke. com
--
http://mail.python.org/mailman/listinfo/python-list
Jun 27 '08 #2
How is it that you recommend killing a pure python thread? And also,
when i use the 'threading' module am I creating a process, or a (gasp)
thread? (Is this an obvious question - and if so, how does one create
a 'process'?)

Thanks!
Jun 27 '08 #3
blaine <fr*****@gmail. comwrites:
How is it that you recommend killing a pure python thread? And also,
when i use the 'threading' module am I creating a process, or a (gasp)
thread?
A thread.
(Is this an obvious question - and if so, how does one create
a 'process'?)
os.fork()
Jun 27 '08 #4
En Mon, 19 May 2008 20:07:06 -0300, Paul Rubin
<"http://phr.cx"@NOSPAM. invalidescribió :
blaine <fr*****@gmail. comwrites:
>How is it that you recommend killing a pure python thread?
Make the thread cooperate. It should periodically check some variable or
condition, and cleanly exit when requested.
>And also,
when i use the 'threading' module am I creating a process, or a (gasp)
thread?

A thread.
>(Is this an obvious question - and if so, how does one create
a 'process'?)

os.fork()
A more portable answer: using the subprocess module.

--
Gabriel Genellina

Jun 27 '08 #5
On May 19, 8:16 pm, "Gabriel Genellina" <gagsl-...@yahoo.com.a r>
wrote:
En Mon, 19 May 2008 20:07:06 -0300, Paul Rubin
<"http://phr.cx"@NOSPAM. invalidescribió :
blaine <frik...@gmail. comwrites:
How is it that you recommend killing a pure python thread?

Make the thread cooperate. It should periodically check some variable or
condition, and cleanly exit when requested.
And also,
when i use the 'threading' module am I creating a process, or a (gasp)
thread?
A thread.
(Is this an obvious question - and if so, how does one create
a 'process'?)
os.fork()

A more portable answer: using the subprocess module.

--
Gabriel Genellina
Thanks for the info. The problem that I'm having is that I get a
thread stuck blocking - waiting for a return from a FIFO (made with
os.mkfifo()).

Blaine
Jun 27 '08 #6
On May 19, 11:31 am, "Chris Mellon" <arka...@gmail. comwrote:
On Mon, May 19, 2008 at 11:36 AM, Roger Heathcote
Fair point, but for sub processes that need to be in close contact with the
original app, or very small functions that you'd like 100s or 1000s of it
seems like a kludge having to spawn whole new processes build in socket
communications and kill via explicit OS calls. I can't see that approach
scaling particularly well but I guess there's no choice.

It's not a kludge - the whole reason why killing a thread is undefined
and a "cardinal sin" is because it's in your own address space and you
can't guarantee anything about how it left things when you killed it.
You simply can't have it both ways. If you want to be able to safely
and sanely kill an uncooperative thread (*especially* third party code
you don't control) you have to isolate it from your address space, and
this means a process. This is a fundamental problem with the entire
idea of shared-state concurrency. For the record, you can't use 1000s
of threads either - if you really need 1000s of concurrent things
running you need to re-think your concurrency model and possibly your
choice of languages and environment.
Strictly speaking, you CAN use 1000s of threads, but it requires some
special effort.

It's not a good idea though, at least for the near future. If you
want to kill a thread you have to do it cooperatively, and for the
effort required to get that right you might as well make the whole
thing event-driven.

The messiness of the real world is *why* you should use processes, not
a reason to avoid them.
Does anyone think it likely that the threading module (and threading in
general) will be improved and augmented with features like timeouts and
arbitrary threadicide in the next year or two? Seems there's little scope
for tapping the power of the current generation of multiple cores with the
current pythons, tho I appreciate breakneck speed has never been a design
objective it looks like multicore is set to be the next generation PC
architecture.

They absolutely should not be. Adding an API which can't work in the
general case and is dangerous even when it can work does not do anyone
any favors.
I agree, if it's not safe there's no point adding it.

However, if you change the parameters a little bit.. it's quite
possible to redefine many blocking functions as cooperative
cancellation points. This is the approach I take with python-
safethread, and it should satisfy most purposes.
Jun 27 '08 #7

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

Similar topics

6
7070
by: Fabiano Sidler | last post by:
Hello Newsgroup! In my Python script, I use the 'thread' module (not 'threading') and 'signal' simultaneously. All spawned threads execute 'pcapObject.loop(-1, callback)', which does not return. The problem now is: When the script catch a signal (let's say: SIGHUP), only the main thread is affected. But I need also the subthreads to be ended, because the script reopen()s files on SIGHUP and would also re-create the threads.
26
2534
by: djw | last post by:
Hi, Folks- I have a question regarding the "proper" use of try: finally:... Consider some code like this: d = Device.open() try: d.someMethodThatCanRaiseError(...) if SomeCondition: raise Error # Error is subclass of Exception
10
9901
by: Jacek Pop³awski | last post by:
Hello. I am going to write python script which will read python command from socket, run it and return some values back to socket. My problem is, that I need some timeout. I need to say for example: os.system("someapplication.exe") and kill it, if it waits longer than let's say 100 seconds
22
5081
by: nd02tsk | last post by:
Hello! I have a couple of final ( I hope, for your sake ) questions regarding PostgreSQL. I understand PostgreSQL uses processes rather than threads. I found this statement in the archives: "The developers agree that multiple processes provide more benefits (mostly in stability and robustness) than costs (more
51
54928
by: Hans | last post by:
Hi all, Is there a way that the program that created and started a thread also stops it. (My usage is a time-out). E.g. thread = threading.Thread(target=Loop.testLoop) thread.start() # This thread is expected to finish within a second
18
10255
by: =?Utf-8?B?VGhlU2lsdmVySGFtbWVy?= | last post by:
Because C# has no native SSH class, I am using SharpSSH. Sometimes, for reasons I do not know, a Connect call will totally lock up the thread and never return. I am sure it has something to do with weirdness going on with the server I am talking to. Anyhow, this locked up state happens once in a while (maybe once per day) and I can't figure out how to deal with the locked up thread. If I issue a Thread.Abort() the exception never...
1
10396
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgS2lxdWVuZXQ=?= | last post by:
Hi misters, Is it possible "kill" the thread of Backgroundworker ? In my Dowork event, I have NOT While for do e.Cancel = true, only have a call to external COM. If I want cancel, calling CancelAsync, not cancels the call to COM. How I can do it , please ? Any suggestions will be very appreciated.
6
5740
by: BlueBird | last post by:
Hi, I have a program with a master thread and several slave threads. Whenever an exception occurs, in the master thread or in one of the slave threads, I would like to interrupt all the threads and the main program. Threading API does not seem to provide a way to stop a thread, is there anyway to achieve that ? The closest thing I found is thread.interrupt_main() but it's far from
7
6149
by: dmitrey | last post by:
hi all, Is there a better way to kill threading.Thread (running) instance than this one http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496960 (it's all I have found via google). BTW, it should be noticed that lots of threading module methods have no docstrings (in my Python 2.5), for example _Thread__bootstrap, _Thread__stop.
0
9942
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
11142
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
9574
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7971
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7129
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
5797
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
4612
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
4220
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3233
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.