• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

LudovicRousseau / pyscard-devel / 14228676560
65%

Build:
DEFAULT BRANCH: master
Ran 02 Apr 2025 08:13PM UTC
Jobs 20
Files 76
Run time 1min
Badge
Embed ▾
README BADGES
x

If you need to use a raster PNG badge, change the '.svg' to '.png' in the link

Markdown

Textile

RDoc

HTML

Rst

02 Apr 2025 08:02PM UTC coverage: 63.143% (-0.03%) from 63.176%
14228676560

push

github

LudovicRousseau
Add an explicit .close() method to CardConnection()

Thanks to Mike Kazantsev for the bug report
"PCSCCardConnection.__del__ method raises exceptions that cannot be easily handled in python code. #223"
Closes: https://github.com/LudovicRousseau/pyscard/issues/223

Describe the bug

PCSCCardConnection.__del__ method raises exceptions that cannot be
easily handled in python code.

To Reproduce

I have a code that does something along the lines of:

req = smartcard.CardRequest.CardRequest(...)
svc = req.waitforcard()
svc.connection.connect()
svc.connection.transmit(cmd)
svc.connection.disconnect()
sleep(...)
exit()

Sometimes this raises following exception:

Exception ignored in: <function PCSCCardConnection.__del__ at 0x7fad81c78fe0>
Traceback (most recent call last):
  File "/usr/lib/python3.13/site-packages/smartcard/pcsc/PCSCCardConnection.py", line 90, in __del__
    raise CardConnectionException(
smartcard.Exceptions.CardConnectionException: Failed to release context: Service not available.: Service not available. (0x8010001D)

As far as I can tell, it gets raised during python's internal garbage
collection, so cannot easily be handled by code, as GC is supposed to
not be directly controlled by python code (aside from some hacks in "gc"
module and ordering duarantees iirc).

Expected behavior

Context can be closed manually within the usual try: ... except: ...
statements, so that any exceptions raised when closing it can be handled
properly.

Additional context

Workaround can be using del svc or such statements, but there's no
guarantee it'd trigger GC, and pretty sure they won't call __del__
method within try-except context anyway, resulting in same uncatchable
exception, just at a different time.

Running SCardReleaseContext(svc.connection.component.hcontext) looks
like going too deep into internals, and hence a bad way to do it, and
does not solve the issue, as it guarantees that __del__ method will now
fail with "Invalid handle." error.
But ... (continued)

103 of 481 branches covered (21.41%)

Branch coverage included in aggregate %.

2 of 9 new or added lines in 2 files covered. (22.22%)

2 existing lines in 2 files now uncovered.

4442 of 6717 relevant lines covered (66.13%)

4.64 hits per line

New Missed Lines in Diff

Lines Coverage ∆ File
1
48.65
0.08% src/smartcard/CardConnectionDecorator.py
6
10.31
0.31% src/smartcard/pcsc/PCSCCardConnection.py

Uncovered Existing Lines

Lines Coverage ∆ File
1
10.31
0.31% src/smartcard/pcsc/PCSCCardConnection.py
1
85.53
-0.25% .tox/py3.13/Lib/site-packages/smartcard/scard/scard.py
Jobs
ID Job ID Ran Files Coverage
1 14228676560.1 02 Apr 2025 08:13PM UTC 67
44.37
GitHub Action Run
2 14228676560.2 02 Apr 2025 08:13PM UTC 67
44.14
GitHub Action Run
3 14228676560.3 02 Apr 2025 08:13PM UTC 67
42.22
GitHub Action Run
4 14228676560.4 02 Apr 2025 08:13PM UTC 67
27.22
GitHub Action Run
5 14228676560.5 02 Apr 2025 08:13PM UTC 67
44.37
GitHub Action Run
6 14228676560.6 02 Apr 2025 08:13PM UTC 67
44.37
GitHub Action Run
7 14228676560.7 02 Apr 2025 08:13PM UTC 67
42.46
GitHub Action Run
8 14228676560.8 02 Apr 2025 08:14PM UTC 67
44.14
GitHub Action Run
9 14228676560.9 02 Apr 2025 08:14PM UTC 67
44.14
GitHub Action Run
10 14228676560.10 02 Apr 2025 08:14PM UTC 67
44.37
GitHub Action Run
11 14228676560.11 02 Apr 2025 08:15PM UTC 67
42.0
GitHub Action Run
12 14228676560.12 02 Apr 2025 08:15PM UTC 67
43.91
GitHub Action Run
13 14228676560.13 02 Apr 2025 08:15PM UTC 67
43.91
GitHub Action Run
14 14228676560.14 02 Apr 2025 08:15PM UTC 67
43.91
GitHub Action Run
15 14228676560.15 02 Apr 2025 08:15PM UTC 67
31.14
GitHub Action Run
16 14228676560.16 02 Apr 2025 08:16PM UTC 67
43.91
GitHub Action Run
17 14228676560.17 02 Apr 2025 08:16PM UTC 67
43.91
GitHub Action Run
18 14228676560.18 02 Apr 2025 08:16PM UTC 67
42.0
GitHub Action Run
19 14228676560.19 02 Apr 2025 08:16PM UTC 67
43.91
GitHub Action Run
20 14228676560.20 02 Apr 2025 08:17PM UTC 67
26.24
GitHub Action Run
Source Files on build 14228676560
  • Tree
  • List 76
  • Changed 5
  • Source Changed 3
  • Coverage Changed 4
Coverage ∆ File Lines Relevant Covered Missed Hits/Line Branch Hits Branch Misses
  • Back to Repo
  • Github Actions Build #14228676560
  • 5d50702b on github
  • Prev Build on master (#14132186882)
  • Next Build on master (#14251842065)
  • Delete
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc