Closed sigsergv closed 7 years ago
I was not able to reproduce the problem on Debian using Python3:
$ python3 ./a.py
Traceback (most recent call last):
File "./a.py", line 11, in <module>
cardservice = cardrequest.waitforcard()
File "/usr/local/lib/python3.4/dist-packages/pyscard-1.9.5-py3.4-linux-x86_64.egg/smartcard/CardRequest.py", line 68, in waitforcard
return self.pcsccardrequest.waitforcard()
File "/usr/local/lib/python3.4/dist-packages/pyscard-1.9.5-py3.4-linux-x86_64.egg/smartcard/pcsc/PCSCCardRequest.py", line 208, in waitforcard
raise CardRequestTimeoutException()
smartcard.Exceptions.CardRequestTimeoutException: Time-out during card request
or on macOS Sierra 10.12 using Python2. I get the same result as above.
I will try later using Python3 on macOS.
What version of PySCard are you using? 1.9.5? What version of macOS are you using? 10.6? This is a quiet old version.
Can you try with a recent version of macOS?
I've installed python-3.6.1 and problem is gone. Maybe it is python-3.5 fault, I was able to reproduce it on linux with python3.5:
% ./test.py
Exception ignored in: <bound method CardService.__del__ of <smartcard.PassThruCardService.PassThruCardService object at 0xb7058d0c>>
Traceback (most recent call last):
File "/home/sigsergv/tmp/test-venv/lib/python3.5/site-packages/smartcard/CardService.py", line 52, in __del__
File "/home/sigsergv/tmp/test-venv/lib/python3.5/site-packages/smartcard/CardConnectionDecorator.py", line 58, in disconnect
File "/home/sigsergv/tmp/test-venv/lib/python3.5/site-packages/smartcard/pcsc/PCSCCardConnection.py", line 154, in disconnect
File "/home/sigsergv/tmp/test-venv/lib/python3.5/site-packages/smartcard/scard/scard.py", line 547, in SCardDisconnect
AttributeError: 'NoneType' object has no attribute 'SCardDisconnect'
Exception ignored in: <bound method PCSCCardConnection.__del__ of <smartcard.pcsc.PCSCCardConnection.PCSCCardConnection object at 0xb7058c8c>>
Traceback (most recent call last):
File "/home/sigsergv/tmp/test-venv/lib/python3.5/site-packages/smartcard/pcsc/PCSCCardConnection.py", line 88, in __del__
File "/home/sigsergv/tmp/test-venv/lib/python3.5/site-packages/smartcard/pcsc/PCSCCardConnection.py", line 154, in disconnect
File "/home/sigsergv/tmp/test-venv/lib/python3.5/site-packages/smartcard/scard/scard.py", line 547, in SCardDisconnect
AttributeError: 'NoneType' object has no attribute 'SCardDisconnect'
% pip list |grep pyscard
pyscard (1.9.5)
% dpkg -l python3.5
ii python3.5 3.5.3-1 i386
I can reproduce the problem now. I need to have a smart card reader connected.
No problem with Python 2.7.9. Problem with Python 3.4.2 and 3.5.3. I have not tried with Python 3.6.
I guess the problem is related to the way the library is unloaded/uninitialized.
The solution is to explicitly call the destructor before exiting, or when you no longer need cardservice
.
Before the exit()
add the line:
cardservice = None
I tried to change the PySCard code to cleanly exit. That would add complexity and depends on the order the libraries are unloaded. The solution I propose above is much simpler.
hi @LudovicRousseau
can you please check this , i am using python version Python 3.10.12 and Linux Ubuntu
It's not crashing on 3.10 and 3.11.
@rohankumbhar-01 please create a new issue with complete details.
When I use sys.exit() in my program it often throws AttributeError exception.
Test program:
Error:
Looks like the destructor is executing twice when using sys.exit().