Chris,
Two questions? What happens to the external application when the pylons
application is shut down? Does it empty the buffer and block for new input or do
you have a way to shut down the external application from pylons? Secondly, do
clients poll the pylons server or the external application for status?
I'm guessing you meant you return 200 OK not 400. Whether you choose to return a
200 or 201 status is mostly an aesthetic choice, though 201 is a clearer
indication of the result. If you're trying to change the response from 200 to
201 you can manipulate the pylons.response to set its status_code to 201. Hope
this helps you out.
Kochhar
Just to clarify a thing: 201 is CREATED, 202 is ACCEPTED.
Don't send 201 instead of 202 because they have different meanings:
<http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html>
About the matter at hand: we spawn some process in that kind of
situation. Not threads.
If you have scalability issues you can think about using the ampq
protocol with an implementation such as rabbitmq
I'm +1 about using 202 ACCEPTED :-)
--
Lawrence, http://oluyede.org - http://twitter.com/lawrenceoluyede
"It is difficult to get a man to understand
something when his salary depends on not
understanding it" - Upton Sinclair
I meant to say 202 Accepted not 201, that's what you get for trying to remember
HTTP status codes.
I am also leaning towards using processes instead of threads (using the
multiprocessing module) but to play devil's advocate for moment why do you
prefer processes to threads? Secondly, and this is pertinent when spawning
processes, how do you hook into the pylons shutdown process to get the external
process to stop?
Cheers,
- Kochhar
Thanks Ian, that's pretty useful to know about. It doesn't fit my case because
I'm working on server-side APIs, but I'll take a look at the implementation to
see if I can glean some ideas.
- Kochhar
The answer is kind of easy. I do not have computations which would
benefit more from a threading model than from a processing model. Our
Apache frontend uses multiprocesses and our async computations are
done in processes. We do not need to share anything and if we do, we
just copy the data to the process. With an API such as pyprocessing's
or subprocess is kind of easy.
If we do have to go to the reason why I generally don't like threading
with shared state there's a great resource which I suggest to read
from cover to cover:
<http://www.eecs.berkeley.edu/Pubs/TechRpts/2006/EECS-2006-1.html>
It's also useful if you do want to know about pro and cons of the
usual way threads are used. There's nothing bad intrinsecally, it's
the common style of threading some environments taught us which is
bad.
By the way you can combine the two techniques if you have to
> Secondly, and this is pertinent when spawning
> processes, how do you hook into the pylons shutdown process to get the external
> process to stop?
Not sure how to respond to this. Pylons is a framework, it can't be
turned on or shutted down. You can start and stop the web server and
how to sync this process with some "daemon processes" largely depend
on the operating system, and so on.
If you have worker process usually those worker processes are created
on demand. If you need some kind of process pool the processes are
killed by the pool, and so on.
Take a look at: <http://pyprocessing.berlios.de/>
If you use Python 2.6 use the builtin module "multiprocessing",
otherwise you can use the backport of that:
<http://pypi.python.org/pypi/multiprocessing/>
I'm not entirely sure of the compatibility issues between the standard
library version of the package and the original one.
--
Lawrence Oluyede
[eng] http://oluyede.org - http://twitter.com/lawrenceoluyede
[ita] http://neropercaso.it - http://twitter.com/rhymes
I lean towards using processes and skipping shared memory entirely as well.
However, there's no reason that multi-threaded applications can't use
message-passing. This might not be the forum for a processes vs. threads
discussion, though.
>> Secondly, and this is pertinent when spawning
>> processes, how do you hook into the pylons shutdown process to get the external
>> process to stop?
>
> Not sure how to respond to this. Pylons is a framework, it can't be
> turned on or shutted down. You can start and stop the web server and
> how to sync this process with some "daemon processes" largely depend
> on the operating system, and so on.
Sorry, I tend to say pylons when I mean the paste http sever. I'm still green on
the terminology.
> If you have worker process usually those worker processes are created
> on demand. If you need some kind of process pool the processes are
> killed by the pool, and so on.
>
> Take a look at: <http://pyprocessing.berlios.de/>
>
> If you use Python 2.6 use the builtin module "multiprocessing",
> otherwise you can use the backport of that:
> <http://pypi.python.org/pypi/multiprocessing/>
>
> I'm not entirely sure of the compatibility issues between the standard
> library version of the package and the original one.
I've successfully used multiprocessing before in other apps, and I'm fine
spawning worker processes inside of pylons. I just need to be able to shut them
down when pylons^H^H^H^H^H^H the web server shuts down. I guess I can just write
the process pids to the filesystem and use supervisord to send signals. Though,
I would really like that logic to be a part of the pylons application.
I was hoping to find the converse of config/environment.py:load_environment
which I could hook into to unload worker processes.