realtime design

Will Stuyvesant hwlgw at hotmail.com
Mon Oct 14 10:40:26 CEST 2002


[Peter Hansen]
> 
> This sounds like a pretty simple thing to do, using a thread
> to call the function, but that doesn't mean the resulting
> system will in any way be considered "realtime" unless you
> have a fairly simplistic definition.  You can't get around
> the underlying fact that Python itself has aspects that are
> not deterministic, nor that unless you are running on top of
> a realtime operating system, no application can be considered
> realtime, by the usual definitions.  More info required...
> 
> -Peter


Well if you think it is easy, could you please show me how?
Because I can not, probably not enough programming skills here...

There a quite a couple of postings here about using Python itself
for realtime and other aspects.  I think I did not make it clear
that we just want to *model* a realtime system, for designing
purposes.  With that model we can try to do things like
correctness proofs.  To build such a model we need basic building
blocks, and the ``rcall'' function below is one of those building
blocks, but I do not know how to implement it!
The *real* realtime system would be implemented later, probably on
top of a realtime OS, but that is not important now.  The first
goal is to build some kind of simulator for a realtime system.  If
it works with seconds instead of milliseconds that would even be
fine too.


Here is the ``programming contest'' again, can you show how to
program the rcall function so it fits its desciption?
I put some comments around the line to ``replace'', I hope I
explain now more clearly what I am looking for?

--------------- cut here ------------------------------------------
import time

def current_time():
    return time.time() * 1000   # ms since Januari 1 1970

def rcall(ms, func, *args, **kw):
    ''' Return func(*args, **kw), unless over ms milliseconds
    time passes.  In that case return 'timeout' in about ms
    milliseconds plus the time it takes for returning.

    NOT functioning now, just returning func(*args)
    '''
    starttime = current_time()

    # YOUR CODE HERE to replace this line :-)
    returnvalue = func(*args, **kw) # How to set a timelimit here?
                                    # A new thread with func?
    # Just starting a new thread does not take that long, that
    # will stay below ms milliseconds.  The idea is that this line
    # of code should not take over ms milliseconds.  But I do not
    # know how to start a new thread with func(...) and get the
    # result from it if it is finished in time: Suppose func
    # hangs, runs forever, how to kill that thread?
    # Or start another process with func?


    endtime = current_time()
    if endtime - starttime > ms: 
        return 'timeout'
    else: 
        return returnvalue
--------------- cut here ------------------------------------------


'''
QOTD

All great discoveries are made by mistake.
                -- Young
'''



More information about the Python-list mailing list