Which methods passlib releases the GIL?

82 views
Skip to first unread message

Aliane Abdelouahab

unread,
Jan 30, 2015, 4:00:02 PM1/30/15
to passli...@googlegroups.com
Hi,
When using event driven servers, they are single threaded, so, what methods release the GIL in passlib?

here is the question about using Tornado 

Eli Collins

unread,
Jan 31, 2015, 1:34:17 PM1/31/15
to passli...@googlegroups.com
Passlib is pure python, and doesn't deal directly with GIL (or any of the CPython API).  So the only places it should block are when it calls into a C extension...

Calls to stdlib's hashlib -- Pretty much all of passlib's algorithms make LOTS of calls to hashlib.  As of Python 2.7, hashlib supposedly releases the GIL when hashing large messages. But pretty much all passlib's calls have messages < the hash's internal block size; so while the GIL probably isn't released during those calls, they should be very quick, meaning calls to things like pbkdf2_sha256 should return to the VM quite frequently.

Calls to stdlib's crypt.crypt() -- This is used by default on POSIX systems for certain hashes, such as sha256_crypt.  I'm not clear at all as to when / if stdlib releases the GIL while crypt.crypt() is going on... though that would certainly be helpful for longer-running ones such as sha256_crypt.  If you're using sha256_crypt or any passlib algorithm that may use crypt.crypt(), you can make a call to ``sha256_crypt.set_backend("builtin")`` (or equivalent for the respective hash) to force passlib's pure-python version (which use hashlib).

Bcrypt -- Passlib's bcrypt hash relies on one of a two third-party C extensions provide the backend: py-bcrypt (https://pypi.python.org/pypi/py-bcrypt) and bcrypt (https://pypi.python.org/pypi/bcrypt).  From your link, it looks like py-bcrypt  releases the GIL. The other one, bcrypt, is CFFI-based and the CFFI docs indicate all CFFI calls are made without the GIL; so both those options should be safe.

Outside of that, there shouldn't be anything holding the GIL or any other thread locks.


--
You received this message because you are subscribed to the Google Groups "passlib-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to passlib-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Eli Collins   el...@assurancetechnologies.com
Software Development & I.T. Consulting
Assurance Technologies   www.assurancetechnologies.com

Aliane Abdelouahab

unread,
Jan 31, 2015, 9:51:05 PM1/31/15
to passli...@googlegroups.com
ah, thank you!
because I love using pbkdf2_sha256 so that means, that it will be okey to use ThreadPoolExecutor / ProcessPoolExecutor
Reply all
Reply to author
Forward
0 new messages