title: A thread per user on heroku
body: <p>I'm building a python/flask web app, which among other things, allows users to chat over xmpp. I use sleekxmpp for the job, which has a event-driven structure. When a message is received, the xmpp instance will run a method defined to handle incoming messages.</p>
  
  <p>As such each active user will need a thread running to listen for incoming messages. My question is, how do I achieve this on heroku? </p>
  
  <p>I can't really use python-rq for backgrounds jobs, as heroku describes them. Let's say a user starts the chat, then we can enqueue a "xmpp listening" job for execution. The worker then retrieves the job, and starts listening for incoming messages. The worker won't return until the chat is over, thus blocking the queue for other chat users. You could have a worker for each chatting user, but that would be hugely expensive (given what heroku charges for a worker process).</p>
  
  <p>I guess what I need is a job queue, where a worker can start a thread for the job and then execute another job from the queue, before the first job is finished. A single worker can then listen for incoming messages for many users at a time.</p>
  
  <p>Is this possible? Or how else should I go about doing this on heroku?</p>