SCardFace is thread-safe, it means that it can be safely implemented using the threading module.
In fact, SCardFace already implements several classes from this module.
When initialising a SCard instance, exclusive access to the card is requested, resulting in having that instance of SCard to be the only object interfacing with the smart card.
It is not possible to establish a smart card connection, when requesting a shared access to the card.
The with stament can be used on SCard instances:
h = SCard( timeout = 30)
with h:
h.send ( select_application_cmd )
h.send ( get_records_cmd)
The with statement acquires a threading.Lock object, and releases it when leaving the block, ensuring that the current thread is the only one to gain access to the smartcard resource.
Note
If several threads use the with statement on the same SCard object, this will serialize the access and as a consequence block all threads but one.
Upon exit of the block, the lock is released.