Hi Michael,
I'm also fairly new to tornado, however I have several background
tasks which need to be handled and sent up to their respective client
when something eventful happens.
What I use is Redis, for messaging between listeners (tornado) and
workers (normal python threads).. I have a master class which spawns
the listener(s) and workers, and use a Redis list to queue up the jobs
(only one worker gets an element, to ensure two workers not working on
the same thing). Then, each listener thread subscribes to a Redis
subscription channel. When the worker is done, it broadcasts it's
results to the channel applicable to the client it was working for,
and immediately goes back to the queue to get another job.
For your scenario, you could have a subscription channel per client,
and everytime a new client comes into the mix, you pop on a job for
them on the worker queue. When the listener gets a message on their
subscription channel (worker is completed) it sends the results back
to the client and re-adds the client job to the worker queue. This way
you could have any number of workers (I don't think it's a good idea
to have one per-client, that could get really messy) and they
continually are checking mail for the clients as soon as they are
freed up.
Redis is really fast (stays in memory) and there are async client
libraries so you don't even have to wait for the job to be posted.
Cheers
nick