Closed Skill3t closed 4 months ago
This patch should fix the problem
--- a/smartcard/CardMonitoring.py
+++ b/smartcard/CardMonitoring.py
@@ -28,7 +28,7 @@ along with pyscard; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
"""
-from threading import Thread, Event
+from threading import Thread, Event, Lock
from time import sleep
import traceback
@@ -123,10 +123,12 @@ class CardMonitor(object):
# the singleton
instance = None
+ lock = Lock()
def __init__(self):
- if not CardMonitor.instance:
- CardMonitor.instance = CardMonitor.__CardMonitorSingleton()
+ with CardMonitor.lock:
+ if not CardMonitor.instance:
+ CardMonitor.instance = CardMonitor.__CardMonitorSingleton()
def __getattr__(self, name):
return getattr(self.instance, name)
Please test and confirm it is OK for you.
Hey Ludovic, thanks a lot yes this fix the Problem. To be honest for my Produktion setup I will use pyscard single thread to avoid this type of problem.
The CardMonitor is implemented as singleton, so I want to add in different thread new observers. But if I do this really quickly the CardMonitor contains only one CardObserver
If you start the script you will see 2 observers. But when you change use_staggered_observer_boot=False only one observers is in the CardMonitor
So my questtion is: is pyscard thread save? If not where can i find this information in the documatation or could this be addes?
thanks a lot in advance