realtime design
Will Stuyvesant
hwlgw at hotmail.com
Mon Oct 14 10:29:20 EDT 2002
After spending a day on trying to find a solution using threads, I
found out there is probably none. Argh!
The problem:
I am trying to come up with a method to run a function in such a way
that the whole thing will take at most x milliseconds, with x a
reasonable value like 200. If the function is not finished by that
time, a default value should be used. If the function *does* finish
in time, the return value of the function should be used. The main
point is that the calling program should be able to continue with
the next statement after x milliseconds. And it would be nice if
the called function is interrupted or something if it has not
finished, so it will not eat CPU resources.
But I found this:
From: Tim Peters (tim.one at home.com)
Subject: RE: embedded python - cancel "while 1: pass"
Newsgroups: comp.lang.python
Date: 2001-01-08 00:07:17 PST
Java's thread .stop(), .resume(), and .suspend() methods were all
deprecated, because they proved to be "inherently unsafe" in
practice. This isn't real surprising: a thread is cheaper than an
OS process largely because the runtime *doesn't* save enough info
to clean up a thread safely, short of the death of the process
it's running in.
Aha! So what I am trying to do is basically impossible with threads!
I guess some people have been here before. Anyway, thank you Tim
Peters. There should be a collection with Tim Peters' c.l.p.
postings you can search on subject. His postings have been useful for
me before! I found this one using google groups search.
What I am going to look into is how to write a function that will
start the target function in another *process* in Windows, and use a
default value if the process does not finish in time.
Any ideas?
and-now-I-am-thinking-about-how-to-kill-a-Windows-process-ly y'rs
'''
Multithreading will rot your teeth.
-- Michael Swaine
'''
More information about the Python-list
mailing list