I’m using PBKDF2, but this applies equally to BCrypt.
Hashing a password with a reasonable number of iterations can easily block for 0.5 seconds. What is a lightweight way to take this out of process? I’m reluctant to setup something like Celery or Gearman just for this operation.
You could use a thread. This will not block tornado. Say that you have a handler that hashes passwords. Then the two relevant methods might look like this:
You could either wait for the thread to finish in the
on_messagemethod then write the response, or if you don’t need to send a response then just let it finish and save the results in thehash_passwordmethod.If you do wait for the thread to finish you have to be careful how you do it.
time.sleepwill block so you will want to use tornado’s non blocking wait instead.