python's threading has no "interrupt"?

Jay O'Connor joconnor at cybermesa.com
Tue Dec 2 16:48:41 CET 2003


Dave Brueck wrote:

>What's your actual use case (IOW, what programming problem are you trying to
>solve)? Maybe there is a Python solution that will work for you, but in order
>to help you find it, people here will need to better understand what you're
>trying to do.
>
>You've noticed that there isn't an identical construct for what you were doing
>in Java, so it may be that the Python way will be a completely different
>approach to the problem rather than just a direct conversion from Java to
>Python syntax.
>  
>


Well, I'll give an example from something I tried to do a few years ago 
which I couldn't translate to Python, though I took a stab at it.

The language in question was a VM language with it's own internal 
process model.  The process model was all inteneral to on eOS process to 
it was a cooperative model of multi-threading

The application I wrote was a web server on the front of an application 
so that web requests were all handled in the application.  IOW, the 
application had a web server interface)

The language process model had both the ability to set process 
priorities, as well as allow processes to sleep and cede control to 
other processes.

When a web request would come in, the handling of the request would be 
forked as a seperate process so that the server could accept the next 
request.  Both the server process and the handling process(es) were at 
the same priority level so in theory each process would run to 
completion before allowing another process to run.  For this reason, 
both the server process and the handling processes would issue a 'yield' 
at periodic strategic points, allowing themselves to temporarily halt 
and for the next process of equal priority that was waiting to run.   
This allowed both the server to remain responsive and all handling 
processes to run efficiently.

Behind all of this was a higher priority process running, but it 
basically would sleep for several minutes (sleeping allowed lower 
priority process, like the server process to run).  When the background 
process would wake up, since it was a higher priority, it would 
immediately take control.  It's main job was to check the list of 
handling processes for any that had been running too long (long running 
processes in a web server meant that something had gone wrong) and 
terminate them (freeing up the process and socket resources, etc..).  
Then it (the cleanup process) would go back to sleep and let the lower 
priority processes run.

At one point I attempted to translate this all into Python, but the lack 
of the ability to set process priorities, or for processes to yield 
control to other processes, or an effective way to terminate proceses, 
kept me from doing this.  The Python threading model seemed very 
primitve compared to what I was used to in regards to how threads can be 
controlled.

Rather than being a knock on Python, I would prefer to know how to do 
all this, if it can be done.






More information about the Python-list mailing list