Your thinking on the request ending up blocked while the microthread
runs seems to be on the money.

I suspect you might have to start up a second system thread within
which the stackless microthreads can run.
In fact you might run into some interesting issues if you don't. I as
far as I know mod_python(and i don't know mod_python that far) each
django request will be executed in its own system thread (depending on
you apache setup, forking or threading model). So your microthreads
might get split over a couple of real threads if you kick them off
inside a request. Or even across processes which simply means
stackless channels won't work(i think, not knowing stackless that
well). Having your microthreads spread over a couple of real threads
is not the standard stackless way of running things.

I'm playing with a multi-user type simulation setup where the
stackless is used to update object locations (physics) and also to do
ai scripts. Where the django requests are used to  fetch a view into
the current state of the simulation.

I've been thinking of an architecture of having a thread for stackless
tasklets and then having the requests affect them using channels. With
multicore thats not ideal since with the GIL(Global interpreter lock)
python doesn't play very effectively on multicores.
So another architecture i've been thinking of is having the stackless
microthreads run in their own process. And then have the django
requests do some form of IPC to kick off new microthreads. Or maybe
some form of shared memory could work for me.

I'd say for your problem you simply need to kick of a real system
thread to do your updates/gen a report. I'm always hesitant to just
add threads in applications tho.
So my suggestion would be to have a single threaded process not using
stackless which works away at an inter process queue doing your heavy
processing. Whenever u want some expensive processing in your django
request you just post off a message into your processor's queue. As
for getting results back like in the case of genning a report you
don't want threads at all since the request must block until the
report has been finished. It seems simpler to just do it than involve
another thread since they're not both going to be doing work.

Have a look at 
http://www.stackless.com/pipermail/stackless/2007-February/002282.html
for an example and discussion on stackless and twisted.




On Apr 18, 9:48 pm, Michael K <[EMAIL PROTECTED]> wrote:
> I have a strange question.  If I'm using a stackless version of
> python, could I, in theory, use channels and tasklets within a django
> application/project?
>
> I can't think of any problems, and I've not experienced any issues
> with using the stackless binary to run manage.py, but I'm kind of
> wondering (aloud, I suppose) if one could, say, kick off a bunch of
> database updates (or generate a report) with a tasklet, returning back
> to the django app immediately with a message of "Processing in the
> backend..." or somesuch, without the whole process breaking.
>
> The way I understand stackless, it would probably start blocking at
> the end of the execution of the request, waiting for the tasklet to
> finish, but I'm guessing there might be a way around that.
>
> Either way, I'm going to play around with it this weekend, just wanted
> to get the thoughts of others.
>
> --
> Michael


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to