gurudesh/pytracebugs huggingface dataset:
# Buggy code
def get_ticker_history(self, pair: str, tick_interval: int) -> List[Dict]:
    if tick_interval == 1:
        interval = "oneMin"
    elif tick_interval == 5:
        interval = "fiveMin"
    else:
        raise ValueError("Cannot parse tick_interval: {}".format(tick_interval))

    data = _API_V2.get_candles(pair.replace("_", "-"), interval)
    # This sanity check is necessary because bittrex returns nonsense sometimes
    for prop in ["C", "V", "O", "H", "L", "T"]:
        for tick in data["result"]:
            if prop not in tick.keys():
                logger.warning(
                    "Required property {} not present in response".format(prop)
                )
                return []

    if not data["success"]:
        raise RuntimeError(
            "{message} params=({pair})".format(message=data["message"], pair=pair)
        )

    return data["result"]


# Traceback (TypeError)
Traceback (most recent call last):
File "/usr/bin/freqtrade", line 4, in <module>
main()
File "/usr/lib/python3.6/site-packages/freqtrade/main.py", line 269, in main
app(_CONF)
File "/usr/lib/python3.6/site-packages/freqtrade/main.py", line 249, in app
_process()
File "/usr/lib/python3.6/site-packages/freqtrade/main.py", line 57, in _process
handle_trade(trade)
File "/usr/lib/python3.6/site-packages/freqtrade/main.py", line 137, in handle_trade
current_rate = exchange.get_ticker(trade.pair)['bid']
File "/usr/lib/python3.6/site-packages/freqtrade/exchange.py", line 118, in get_ticker
'bid': float(data['result']['Bid']),
TypeError: float() argument must be a string or a number, not 'NoneType'
2017-10-07 03:55:46,165 - telegram.ext.updater - ERROR - Error while getting Updates: Timed out

# Fixed code
def get_ticker_history(self, pair: str, tick_interval: int) -> List[Dict]:
    if tick_interval == 1:
        interval = "oneMin"
    elif tick_interval == 5:
        interval = "fiveMin"
    else:
        raise ValueError("Cannot parse tick_interval: {}".format(tick_interval))

    data = _API_V2.get_candles(pair.replace("_", "-"), interval)
    # This sanity check is necessary because bittrex returns nonsense sometimes
    for prop in ["C", "V", "O", "H", "L", "T"]:
        for tick in data["result"]:
            if prop not in tick.keys():
                logger.warning("Required property %s not present in response", prop)
                return []

    if not data["success"]:
        raise RuntimeError(
            "{message} params=({pair})".format(message=data["message"], pair=pair)
        )

    return data["result"]
# Buggy code
def gen_pair_whitelist(
    base_currency: str, topn: int = 20, key: str = "BaseVolume"
) -> List[str]:
    """
    Updates the whitelist with with a dynamically generated list
    :param base_currency: base currency as str
    :param topn: maximum number of returned results
    :param key: sort key (defaults to 'BaseVolume')
    :return: List of pairs
    """
    summaries = sorted(
        (
            s
            for s in exchange.get_market_summaries()
            if s["MarketName"].startswith(base_currency)
        ),
        key=lambda s: s[key],
        reverse=True,
    )
    pairs = [s["MarketName"].replace("-", "_") for s in summaries[:topn]]
    logger.debug("Generated pair whitelist: %s ...", pairs)
    return pairs


# Traceback (TypeError)
Traceback (most recent call last):
File "/usr/bin/freqtrade", line 4, in <module>
main()
File "/usr/lib/python3.6/site-packages/freqtrade/main.py", line 269, in main
app(_CONF)
File "/usr/lib/python3.6/site-packages/freqtrade/main.py", line 249, in app
_process()
File "/usr/lib/python3.6/site-packages/freqtrade/main.py", line 57, in _process
handle_trade(trade)
File "/usr/lib/python3.6/site-packages/freqtrade/main.py", line 137, in handle_trade
current_rate = exchange.get_ticker(trade.pair)['bid']
File "/usr/lib/python3.6/site-packages/freqtrade/exchange.py", line 118, in get_ticker
'bid': float(data['result']['Bid']),
TypeError: float() argument must be a string or a number, not 'NoneType'
2017-10-07 03:55:46,165 - telegram.ext.updater - ERROR - Error while getting Updates: Timed out

# Fixed code
def gen_pair_whitelist(
    base_currency: str, topn: int = 20, key: str = "BaseVolume"
) -> List[str]:
    """
    Updates the whitelist with with a dynamically generated list
    :param base_currency: base currency as str
    :param topn: maximum number of returned results
    :param key: sort key (defaults to 'BaseVolume')
    :return: List of pairs
    """
    summaries = sorted(
        (
            s
            for s in exchange.get_market_summaries()
            if s["MarketName"].startswith(base_currency)
        ),
        key=lambda s: s[key],
        reverse=True,
    )
    return [s["MarketName"].replace("-", "_") for s in summaries[:topn]]
# Buggy code
def quote_html(*content, sep=" "):
    """
    Quote HTML symbols

    All <, >, & and " symbols that are not a part of a tag or
    an HTML entity must be replaced with the corresponding HTML entities
    (< with &lt; > with &gt; & with &amp and " with &quot).

    :param content:
    :param sep:
    :return:
    """
    return html_decoration.quote(_join(*content, sep=sep))


# Traceback (AttributeError)
aiogram.utils.markdown.hbold('test')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/.../.virtualenvs/.../lib/python3.8/site-packages/aiogram/utils/markdown.py", line 85, in hbold
return html_decoration.bold.format(
AttributeError: 'function' object has no attribute 'format'

# Fixed code
def quote_html(*content, sep=" ") -> str:
    """
    Quote HTML symbols

    All <, >, & and " symbols that are not a part of a tag or
    an HTML entity must be replaced with the corresponding HTML entities
    (< with &lt; > with &gt; & with &amp and " with &quot).

    :param content:
    :param sep:
    :return:
    """
    return html_decoration.quote(_join(*content, sep=sep))
# Buggy code
def escape_md(*content, sep=" "):
    """
    Escape markdown text

    E.g. for usernames

    :param content:
    :param sep:
    :return:
    """
    return markdown_decoration.quote(_join(*content, sep=sep))


# Traceback (AttributeError)
aiogram.utils.markdown.hbold('test')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/.../.virtualenvs/.../lib/python3.8/site-packages/aiogram/utils/markdown.py", line 85, in hbold
return html_decoration.bold.format(
AttributeError: 'function' object has no attribute 'format'

# Fixed code
def escape_md(*content, sep=" ") -> str:
    """
    Escape markdown text

    E.g. for usernames

    :param content:
    :param sep:
    :return:
    """
    return markdown_decoration.quote(_join(*content, sep=sep))
# Buggy code
def bold(*content, sep=" "):
    """
    Make bold text (Markdown)

    :param content:
    :param sep:
    :return:
    """
    return markdown_decoration.bold.format(
        value=markdown_decoration.quote(_join(*content, sep=sep))
    )


# Traceback (AttributeError)
aiogram.utils.markdown.hbold('test')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/.../.virtualenvs/.../lib/python3.8/site-packages/aiogram/utils/markdown.py", line 85, in hbold
return html_decoration.bold.format(
AttributeError: 'function' object has no attribute 'format'

# Fixed code
def bold(*content, sep=" ") -> str:
    """
    Make bold text (Markdown)

    :param content:
    :param sep:
    :return:
    """
    return markdown_decoration.bold(
        value=markdown_decoration.quote(_join(*content, sep=sep))
    )
# Buggy code
def hbold(*content, sep=" "):
    """
    Make bold text (HTML)

    :param content:
    :param sep:
    :return:
    """
    return html_decoration.bold.format(
        value=html_decoration.quote(_join(*content, sep=sep))
    )


# Traceback (AttributeError)
aiogram.utils.markdown.hbold('test')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/.../.virtualenvs/.../lib/python3.8/site-packages/aiogram/utils/markdown.py", line 85, in hbold
return html_decoration.bold.format(
AttributeError: 'function' object has no attribute 'format'

# Fixed code
def hbold(*content, sep=" ") -> str:
    """
    Make bold text (HTML)

    :param content:
    :param sep:
    :return:
    """
    return html_decoration.bold(value=html_decoration.quote(_join(*content, sep=sep)))
# Buggy code
def italic(*content, sep=" "):
    """
    Make italic text (Markdown)

    :param content:
    :param sep:
    :return:
    """
    return markdown_decoration.italic.format(
        value=markdown_decoration.quote(_join(*content, sep=sep))
    )


# Traceback (AttributeError)
aiogram.utils.markdown.hbold('test')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/.../.virtualenvs/.../lib/python3.8/site-packages/aiogram/utils/markdown.py", line 85, in hbold
return html_decoration.bold.format(
AttributeError: 'function' object has no attribute 'format'

# Fixed code
def italic(*content, sep=" ") -> str:
    """
    Make italic text (Markdown)

    :param content:
    :param sep:
    :return:
    """
    return markdown_decoration.italic(
        value=markdown_decoration.quote(_join(*content, sep=sep))
    )
# Buggy code
def hitalic(*content, sep=" "):
    """
    Make italic text (HTML)

    :param content:
    :param sep:
    :return:
    """
    return html_decoration.italic.format(
        value=html_decoration.quote(_join(*content, sep=sep))
    )


# Traceback (AttributeError)
aiogram.utils.markdown.hbold('test')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/.../.virtualenvs/.../lib/python3.8/site-packages/aiogram/utils/markdown.py", line 85, in hbold
return html_decoration.bold.format(
AttributeError: 'function' object has no attribute 'format'

# Fixed code
def hitalic(*content, sep=" ") -> str:
    """
    Make italic text (HTML)

    :param content:
    :param sep:
    :return:
    """
    return html_decoration.italic(value=html_decoration.quote(_join(*content, sep=sep)))
# Buggy code
def code(*content, sep=" "):
    """
    Make mono-width text (Markdown)

    :param content:
    :param sep:
    :return:
    """
    return markdown_decoration.code.format(
        value=markdown_decoration.quote(_join(*content, sep=sep))
    )


# Traceback (AttributeError)
aiogram.utils.markdown.hbold('test')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/.../.virtualenvs/.../lib/python3.8/site-packages/aiogram/utils/markdown.py", line 85, in hbold
return html_decoration.bold.format(
AttributeError: 'function' object has no attribute 'format'

# Fixed code
def code(*content, sep=" ") -> str:
    """
    Make mono-width text (Markdown)

    :param content:
    :param sep:
    :return:
    """
    return markdown_decoration.code(
        value=markdown_decoration.quote(_join(*content, sep=sep))
    )
# Buggy code
def hcode(*content, sep=" "):
    """
    Make mono-width text (HTML)

    :param content:
    :param sep:
    :return:
    """
    return html_decoration.code.format(
        value=html_decoration.quote(_join(*content, sep=sep))
    )


# Traceback (AttributeError)
aiogram.utils.markdown.hbold('test')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/.../.virtualenvs/.../lib/python3.8/site-packages/aiogram/utils/markdown.py", line 85, in hbold
return html_decoration.bold.format(
AttributeError: 'function' object has no attribute 'format'

# Fixed code
def hcode(*content, sep=" ") -> str:
    """
    Make mono-width text (HTML)

    :param content:
    :param sep:
    :return:
    """
    return html_decoration.code(value=html_decoration.quote(_join(*content, sep=sep)))
# Buggy code
def pre(*content, sep="\n"):
    """
    Make mono-width text block (Markdown)

    :param content:
    :param sep:
    :return:
    """
    return markdown_decoration.pre.format(
        value=markdown_decoration.quote(_join(*content, sep=sep))
    )


# Traceback (AttributeError)
aiogram.utils.markdown.hbold('test')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/.../.virtualenvs/.../lib/python3.8/site-packages/aiogram/utils/markdown.py", line 85, in hbold
return html_decoration.bold.format(
AttributeError: 'function' object has no attribute 'format'

# Fixed code
def pre(*content, sep="\n") -> str:
    """
    Make mono-width text block (Markdown)

    :param content:
    :param sep:
    :return:
    """
    return markdown_decoration.pre(
        value=markdown_decoration.quote(_join(*content, sep=sep))
    )
# Buggy code
def hpre(*content, sep="\n"):
    """
    Make mono-width text block (HTML)

    :param content:
    :param sep:
    :return:
    """
    return html_decoration.pre.format(
        value=html_decoration.quote(_join(*content, sep=sep))
    )


# Traceback (AttributeError)
aiogram.utils.markdown.hbold('test')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/.../.virtualenvs/.../lib/python3.8/site-packages/aiogram/utils/markdown.py", line 85, in hbold
return html_decoration.bold.format(
AttributeError: 'function' object has no attribute 'format'

# Fixed code
def hpre(*content, sep="\n") -> str:
    """
    Make mono-width text block (HTML)

    :param content:
    :param sep:
    :return:
    """
    return html_decoration.pre(value=html_decoration.quote(_join(*content, sep=sep)))
# Buggy code
def underline(*content, sep=" "):
    """
    Make underlined text (Markdown)

    :param content:
    :param sep:
    :return:
    """
    return markdown_decoration.underline.format(
        value=markdown_decoration.quote(_join(*content, sep=sep))
    )


# Traceback (AttributeError)
aiogram.utils.markdown.hbold('test')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/.../.virtualenvs/.../lib/python3.8/site-packages/aiogram/utils/markdown.py", line 85, in hbold
return html_decoration.bold.format(
AttributeError: 'function' object has no attribute 'format'

# Fixed code
def underline(*content, sep=" ") -> str:
    """
    Make underlined text (Markdown)

    :param content:
    :param sep:
    :return:
    """
    return markdown_decoration.underline(
        value=markdown_decoration.quote(_join(*content, sep=sep))
    )
# Buggy code
def hunderline(*content, sep=" "):
    """
    Make underlined text (HTML)

    :param content:
    :param sep:
    :return:
    """
    return html_decoration.underline.format(
        value=html_decoration.quote(_join(*content, sep=sep))
    )


# Traceback (AttributeError)
aiogram.utils.markdown.hbold('test')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/.../.virtualenvs/.../lib/python3.8/site-packages/aiogram/utils/markdown.py", line 85, in hbold
return html_decoration.bold.format(
AttributeError: 'function' object has no attribute 'format'

# Fixed code
def hunderline(*content, sep=" ") -> str:
    """
    Make underlined text (HTML)

    :param content:
    :param sep:
    :return:
    """
    return html_decoration.underline(
        value=html_decoration.quote(_join(*content, sep=sep))
    )
# Buggy code
def strikethrough(*content, sep=" "):
    """
    Make strikethrough text (Markdown)

    :param content:
    :param sep:
    :return:
    """
    return markdown_decoration.strikethrough.format(
        value=markdown_decoration.quote(_join(*content, sep=sep))
    )


# Traceback (AttributeError)
aiogram.utils.markdown.hbold('test')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/.../.virtualenvs/.../lib/python3.8/site-packages/aiogram/utils/markdown.py", line 85, in hbold
return html_decoration.bold.format(
AttributeError: 'function' object has no attribute 'format'

# Fixed code
def strikethrough(*content, sep=" ") -> str:
    """
    Make strikethrough text (Markdown)

    :param content:
    :param sep:
    :return:
    """
    return markdown_decoration.strikethrough(
        value=markdown_decoration.quote(_join(*content, sep=sep))
    )
# Buggy code
def hstrikethrough(*content, sep=" "):
    """
    Make strikethrough text (HTML)

    :param content:
    :param sep:
    :return:
    """
    return html_decoration.strikethrough.format(
        value=html_decoration.quote(_join(*content, sep=sep))
    )


# Traceback (AttributeError)
aiogram.utils.markdown.hbold('test')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/.../.virtualenvs/.../lib/python3.8/site-packages/aiogram/utils/markdown.py", line 85, in hbold
return html_decoration.bold.format(
AttributeError: 'function' object has no attribute 'format'

# Fixed code
def hstrikethrough(*content, sep=" ") -> str:
    """
    Make strikethrough text (HTML)

    :param content:
    :param sep:
    :return:
    """
    return html_decoration.strikethrough(
        value=html_decoration.quote(_join(*content, sep=sep))
    )
# Buggy code
def link(title: str, url: str) -> str:
    """
    Format URL (Markdown)

    :param title:
    :param url:
    :return:
    """
    return markdown_decoration.link.format(
        value=markdown_decoration.quote(title), link=url
    )


# Traceback (AttributeError)
aiogram.utils.markdown.hbold('test')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/.../.virtualenvs/.../lib/python3.8/site-packages/aiogram/utils/markdown.py", line 85, in hbold
return html_decoration.bold.format(
AttributeError: 'function' object has no attribute 'format'

# Fixed code
def link(title: str, url: str) -> str:
    """
    Format URL (Markdown)

    :param title:
    :param url:
    :return:
    """
    return markdown_decoration.link(value=markdown_decoration.quote(title), link=url)
# Buggy code
def hlink(title: str, url: str) -> str:
    """
    Format URL (HTML)

    :param title:
    :param url:
    :return:
    """
    return html_decoration.link.format(value=html_decoration.quote(title), link=url)


# Traceback (AttributeError)
aiogram.utils.markdown.hbold('test')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/.../.virtualenvs/.../lib/python3.8/site-packages/aiogram/utils/markdown.py", line 85, in hbold
return html_decoration.bold.format(
AttributeError: 'function' object has no attribute 'format'

# Fixed code
def hlink(title: str, url: str) -> str:
    """
    Format URL (HTML)

    :param title:
    :param url:
    :return:
    """
    return html_decoration.link(value=html_decoration.quote(title), link=url)
# Buggy code
def __init__(self, config: SimpleConfig):
    ThreadJob.__init__(self)
    # Keyed by xpub.  The value is the device id
    # has been paired, and None otherwise. Needs self.lock.
    self.xpub_ids = {}  # type: Dict[str, str]
    # A list of clients.  The key is the client, the value is
    # a (path, id_) pair. Needs self.lock.
    self.clients = {}  # type: Dict[HardwareClientBase, Tuple[Union[str, bytes], str]]
    # What we recognise.  (vendor_id, product_id) -> Plugin
    self._recognised_hardware = {}  # type: Dict[Tuple[int, int], HW_PluginBase]
    # Custom enumerate functions for devices we don't know about.
    self._enumerate_func = set()  # Needs self.lock.
    # locks: if you need to take multiple ones, acquire them in the order they are defined here!
    self._scan_lock = threading.RLock()
    self.lock = threading.RLock()
    self.hid_lock = _hid_lock

    self.config = config

    global _hid_executor
    if _hid_executor is None:
        _hid_executor = concurrent.futures.ThreadPoolExecutor(
            max_workers=1, thread_name_prefix="hid_enumerate_thread"
        )


# Traceback (OSError)
$ ~/Downloads/apps/electrum-4.0.2-x86_64.AppImage --testnet
Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway.
E | plugin.DeviceMgr | failed to create client for bitbox02 at b'0001:0009:01': Exception('No BitBox02 detected')
E | plugins.coldcard.coldcard.Coldcard_KeyStore |
Traceback (most recent call last):
File "/tmp/.mount_electrcFBIsQ/usr/lib/python3.7/site-packages/electrum/plugins/coldcard/coldcard.py", line 383, in sign_transaction
resp = client.sign_transaction_poll()
File "/tmp/.mount_electrcFBIsQ/usr/lib/python3.7/site-packages/electrum/plugins/coldcard/coldcard.py", line 233, in sign_transaction_poll
return self.dev.send_recv(CCProtocolPacker.get_signed_txn(), timeout=None)
File "/tmp/.mount_electrcFBIsQ/usr/lib/python3.7/site-packages/ckcc/client.py", line 139, in send_recv
buf = self.dev.read(64, timeout_ms=(timeout or 0))
File "hid.pyx", line 123, in hid.device.read
OSError: read error
double free or corruption (fasttop)
Aborted

# Fixed code
def __init__(self, config: SimpleConfig):
    ThreadJob.__init__(self)
    # Keyed by xpub.  The value is the device id
    # has been paired, and None otherwise. Needs self.lock.
    self.xpub_ids = {}  # type: Dict[str, str]
    # A list of clients.  The key is the client, the value is
    # a (path, id_) pair. Needs self.lock.
    self.clients = {}  # type: Dict[HardwareClientBase, Tuple[Union[str, bytes], str]]
    # What we recognise.  (vendor_id, product_id) -> Plugin
    self._recognised_hardware = {}  # type: Dict[Tuple[int, int], HW_PluginBase]
    # Custom enumerate functions for devices we don't know about.
    self._enumerate_func = set()  # Needs self.lock.

    self.lock = threading.RLock()

    self.config = config
# Buggy code
def _close_client(self, id_):
    client = self._client_by_id(id_)
    self.clients.pop(client, None)
    if client:
        client.close()


# Traceback (OSError)
$ ~/Downloads/apps/electrum-4.0.2-x86_64.AppImage --testnet
Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway.
E | plugin.DeviceMgr | failed to create client for bitbox02 at b'0001:0009:01': Exception('No BitBox02 detected')
E | plugins.coldcard.coldcard.Coldcard_KeyStore |
Traceback (most recent call last):
File "/tmp/.mount_electrcFBIsQ/usr/lib/python3.7/site-packages/electrum/plugins/coldcard/coldcard.py", line 383, in sign_transaction
resp = client.sign_transaction_poll()
File "/tmp/.mount_electrcFBIsQ/usr/lib/python3.7/site-packages/electrum/plugins/coldcard/coldcard.py", line 233, in sign_transaction_poll
return self.dev.send_recv(CCProtocolPacker.get_signed_txn(), timeout=None)
File "/tmp/.mount_electrcFBIsQ/usr/lib/python3.7/site-packages/ckcc/client.py", line 139, in send_recv
buf = self.dev.read(64, timeout_ms=(timeout or 0))
File "hid.pyx", line 123, in hid.device.read
OSError: read error
double free or corruption (fasttop)
Aborted

# Fixed code
def _close_client(self, id_):
    with self.lock:
        client = self._client_by_id(id_)
        self.clients.pop(client, None)
    if client:
        client.close()
# Buggy code
def _scan_devices_with_hid(self) -> List["Device"]:
    try:
        import hid
    except ImportError:
        return []

    def hid_enumerate():
        with self.hid_lock:
            return hid.enumerate(0, 0)

    hid_list_fut = _hid_executor.submit(hid_enumerate)
    try:
        hid_list = hid_list_fut.result()
    except (concurrent.futures.CancelledError, concurrent.futures.TimeoutError) as e:
        return []

    devices = []
    for d in hid_list:
        product_key = (d["vendor_id"], d["product_id"])
        if product_key in self._recognised_hardware:
            plugin = self._recognised_hardware[product_key]
            device = plugin.create_device_from_hid_enumeration(
                d, product_key=product_key
            )
            devices.append(device)
    return devices


# Traceback (OSError)
$ ~/Downloads/apps/electrum-4.0.2-x86_64.AppImage --testnet
Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway.
E | plugin.DeviceMgr | failed to create client for bitbox02 at b'0001:0009:01': Exception('No BitBox02 detected')
E | plugins.coldcard.coldcard.Coldcard_KeyStore |
Traceback (most recent call last):
File "/tmp/.mount_electrcFBIsQ/usr/lib/python3.7/site-packages/electrum/plugins/coldcard/coldcard.py", line 383, in sign_transaction
resp = client.sign_transaction_poll()
File "/tmp/.mount_electrcFBIsQ/usr/lib/python3.7/site-packages/electrum/plugins/coldcard/coldcard.py", line 233, in sign_transaction_poll
return self.dev.send_recv(CCProtocolPacker.get_signed_txn(), timeout=None)
File "/tmp/.mount_electrcFBIsQ/usr/lib/python3.7/site-packages/ckcc/client.py", line 139, in send_recv
buf = self.dev.read(64, timeout_ms=(timeout or 0))
File "hid.pyx", line 123, in hid.device.read
OSError: read error
double free or corruption (fasttop)
Aborted

# Fixed code
def _scan_devices_with_hid(self) -> List["Device"]:
    try:
        import hid
    except ImportError:
        return []

    devices = []
    for d in hid.enumerate(0, 0):
        product_key = (d["vendor_id"], d["product_id"])
        if product_key in self._recognised_hardware:
            plugin = self._recognised_hardware[product_key]
            device = plugin.create_device_from_hid_enumeration(
                d, product_key=product_key
            )
            devices.append(device)
    return devices
# Buggy code
def close(self):
    with self.device_manager().hid_lock:
        try:
            self.bitbox02_device.close()
        except:
            pass


# Traceback (OSError)
$ ~/Downloads/apps/electrum-4.0.2-x86_64.AppImage --testnet
Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway.
E | plugin.DeviceMgr | failed to create client for bitbox02 at b'0001:0009:01': Exception('No BitBox02 detected')
E | plugins.coldcard.coldcard.Coldcard_KeyStore |
Traceback (most recent call last):
File "/tmp/.mount_electrcFBIsQ/usr/lib/python3.7/site-packages/electrum/plugins/coldcard/coldcard.py", line 383, in sign_transaction
resp = client.sign_transaction_poll()
File "/tmp/.mount_electrcFBIsQ/usr/lib/python3.7/site-packages/electrum/plugins/coldcard/coldcard.py", line 233, in sign_transaction_poll
return self.dev.send_recv(CCProtocolPacker.get_signed_txn(), timeout=None)
File "/tmp/.mount_electrcFBIsQ/usr/lib/python3.7/site-packages/ckcc/client.py", line 139, in send_recv
buf = self.dev.read(64, timeout_ms=(timeout or 0))
File "hid.pyx", line 123, in hid.device.read
OSError: read error
double free or corruption (fasttop)
Aborted

# Fixed code
def close(self):
    try:
        self.bitbox02_device.close()
    except:
        pass
# Buggy code
def pairing_step(code: str, device_response: Callable[[], bool]) -> bool:
    msg = "Please compare and confirm the pairing code on your BitBox02:\n" + code
    self.handler.show_message(msg)
    try:
        res = device_response()
    except:
        # Close the hid device on exception
        with self.device_manager().hid_lock:
            hid_device.close()
        raise
    finally:
        self.handler.finished()
    return res


# Traceback (OSError)
$ ~/Downloads/apps/electrum-4.0.2-x86_64.AppImage --testnet
Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway.
E | plugin.DeviceMgr | failed to create client for bitbox02 at b'0001:0009:01': Exception('No BitBox02 detected')
E | plugins.coldcard.coldcard.Coldcard_KeyStore |
Traceback (most recent call last):
File "/tmp/.mount_electrcFBIsQ/usr/lib/python3.7/site-packages/electrum/plugins/coldcard/coldcard.py", line 383, in sign_transaction
resp = client.sign_transaction_poll()
File "/tmp/.mount_electrcFBIsQ/usr/lib/python3.7/site-packages/electrum/plugins/coldcard/coldcard.py", line 233, in sign_transaction_poll
return self.dev.send_recv(CCProtocolPacker.get_signed_txn(), timeout=None)
File "/tmp/.mount_electrcFBIsQ/usr/lib/python3.7/site-packages/ckcc/client.py", line 139, in send_recv
buf = self.dev.read(64, timeout_ms=(timeout or 0))
File "hid.pyx", line 123, in hid.device.read
OSError: read error
double free or corruption (fasttop)
Aborted

# Fixed code
def pairing_step(code: str, device_response: Callable[[], bool]) -> bool:
    msg = "Please compare and confirm the pairing code on your BitBox02:\n" + code
    self.handler.show_message(msg)
    try:
        res = device_response()
    except:
        # Close the hid device on exception
        hid_device.close()
        raise
    finally:
        self.handler.finished()
    return res
# Buggy code
def __init__(self, plugin, handler, dev_path, *, is_simulator=False):
    HardwareClientBase.__init__(self, plugin=plugin)
    self.device = plugin.device
    self.handler = handler

    # if we know what the (xfp, xpub) "should be" then track it here
    self._expected_device = None

    if is_simulator:
        self.dev = ElectrumColdcardDevice(dev_path, encrypt=True)
    else:
        # open the real HID device
        with self.device_manager().hid_lock:
            hd = hid.device(path=dev_path)
            hd.open_path(dev_path)

        self.dev = ElectrumColdcardDevice(dev=hd, encrypt=True)


# Traceback (OSError)
$ ~/Downloads/apps/electrum-4.0.2-x86_64.AppImage --testnet
Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway.
E | plugin.DeviceMgr | failed to create client for bitbox02 at b'0001:0009:01': Exception('No BitBox02 detected')
E | plugins.coldcard.coldcard.Coldcard_KeyStore |
Traceback (most recent call last):
File "/tmp/.mount_electrcFBIsQ/usr/lib/python3.7/site-packages/electrum/plugins/coldcard/coldcard.py", line 383, in sign_transaction
resp = client.sign_transaction_poll()
File "/tmp/.mount_electrcFBIsQ/usr/lib/python3.7/site-packages/electrum/plugins/coldcard/coldcard.py", line 233, in sign_transaction_poll
return self.dev.send_recv(CCProtocolPacker.get_signed_txn(), timeout=None)
File "/tmp/.mount_electrcFBIsQ/usr/lib/python3.7/site-packages/ckcc/client.py", line 139, in send_recv
buf = self.dev.read(64, timeout_ms=(timeout or 0))
File "hid.pyx", line 123, in hid.device.read
OSError: read error
double free or corruption (fasttop)
Aborted

# Fixed code
def __init__(self, plugin, handler, dev_path, *, is_simulator=False):
    HardwareClientBase.__init__(self, plugin=plugin)
    self.device = plugin.device
    self.handler = handler

    # if we know what the (xfp, xpub) "should be" then track it here
    self._expected_device = None

    if is_simulator:
        self.dev = ElectrumColdcardDevice(dev_path, encrypt=True)
    else:
        # open the real HID device
        hd = hid.device(path=dev_path)
        hd.open_path(dev_path)

        self.dev = ElectrumColdcardDevice(dev=hd, encrypt=True)
# Buggy code
def close(self):
    # close the HID device (so can be reused)
    with self.device_manager().hid_lock:
        self.dev.close()
    self.dev = None


# Traceback (OSError)
$ ~/Downloads/apps/electrum-4.0.2-x86_64.AppImage --testnet
Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway.
E | plugin.DeviceMgr | failed to create client for bitbox02 at b'0001:0009:01': Exception('No BitBox02 detected')
E | plugins.coldcard.coldcard.Coldcard_KeyStore |
Traceback (most recent call last):
File "/tmp/.mount_electrcFBIsQ/usr/lib/python3.7/site-packages/electrum/plugins/coldcard/coldcard.py", line 383, in sign_transaction
resp = client.sign_transaction_poll()
File "/tmp/.mount_electrcFBIsQ/usr/lib/python3.7/site-packages/electrum/plugins/coldcard/coldcard.py", line 233, in sign_transaction_poll
return self.dev.send_recv(CCProtocolPacker.get_signed_txn(), timeout=None)
File "/tmp/.mount_electrcFBIsQ/usr/lib/python3.7/site-packages/ckcc/client.py", line 139, in send_recv
buf = self.dev.read(64, timeout_ms=(timeout or 0))
File "hid.pyx", line 123, in hid.device.read
OSError: read error
double free or corruption (fasttop)
Aborted

# Fixed code
def close(self):
    # close the HID device (so can be reused)
    self.dev.close()
    self.dev = None
# Buggy code
def close(self):
    if self.opened:
        with self.device_manager().hid_lock:
            try:
                self.dbb_hid.close()
            except:
                pass
    self.opened = False


# Traceback (OSError)
$ ~/Downloads/apps/electrum-4.0.2-x86_64.AppImage --testnet
Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway.
E | plugin.DeviceMgr | failed to create client for bitbox02 at b'0001:0009:01': Exception('No BitBox02 detected')
E | plugins.coldcard.coldcard.Coldcard_KeyStore |
Traceback (most recent call last):
File "/tmp/.mount_electrcFBIsQ/usr/lib/python3.7/site-packages/electrum/plugins/coldcard/coldcard.py", line 383, in sign_transaction
resp = client.sign_transaction_poll()
File "/tmp/.mount_electrcFBIsQ/usr/lib/python3.7/site-packages/electrum/plugins/coldcard/coldcard.py", line 233, in sign_transaction_poll
return self.dev.send_recv(CCProtocolPacker.get_signed_txn(), timeout=None)
File "/tmp/.mount_electrcFBIsQ/usr/lib/python3.7/site-packages/ckcc/client.py", line 139, in send_recv
buf = self.dev.read(64, timeout_ms=(timeout or 0))
File "hid.pyx", line 123, in hid.device.read
OSError: read error
double free or corruption (fasttop)
Aborted

# Fixed code
def close(self):
    if self.opened:
        try:
            self.dbb_hid.close()
        except:
            pass
    self.opened = False
# Buggy code
def get_dbb_device(self, device):
    with self.device_manager().hid_lock:
        dev = hid.device()
        dev.open_path(device.path)
    return dev


# Traceback (OSError)
$ ~/Downloads/apps/electrum-4.0.2-x86_64.AppImage --testnet
Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway.
E | plugin.DeviceMgr | failed to create client for bitbox02 at b'0001:0009:01': Exception('No BitBox02 detected')
E | plugins.coldcard.coldcard.Coldcard_KeyStore |
Traceback (most recent call last):
File "/tmp/.mount_electrcFBIsQ/usr/lib/python3.7/site-packages/electrum/plugins/coldcard/coldcard.py", line 383, in sign_transaction
resp = client.sign_transaction_poll()
File "/tmp/.mount_electrcFBIsQ/usr/lib/python3.7/site-packages/electrum/plugins/coldcard/coldcard.py", line 233, in sign_transaction_poll
return self.dev.send_recv(CCProtocolPacker.get_signed_txn(), timeout=None)
File "/tmp/.mount_electrcFBIsQ/usr/lib/python3.7/site-packages/ckcc/client.py", line 139, in send_recv
buf = self.dev.read(64, timeout_ms=(timeout or 0))
File "hid.pyx", line 123, in hid.device.read
OSError: read error
double free or corruption (fasttop)
Aborted

# Fixed code
def get_dbb_device(self, device):
    dev = hid.device()
    dev.open_path(device.path)
    return dev
# Buggy code
def __init__(self, *, plugin: "HW_PluginBase"):
    self.plugin = plugin


# Traceback (OSError)
$ ~/Downloads/apps/electrum-4.0.2-x86_64.AppImage --testnet
Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway.
E | plugin.DeviceMgr | failed to create client for bitbox02 at b'0001:0009:01': Exception('No BitBox02 detected')
E | plugins.coldcard.coldcard.Coldcard_KeyStore |
Traceback (most recent call last):
File "/tmp/.mount_electrcFBIsQ/usr/lib/python3.7/site-packages/electrum/plugins/coldcard/coldcard.py", line 383, in sign_transaction
resp = client.sign_transaction_poll()
File "/tmp/.mount_electrcFBIsQ/usr/lib/python3.7/site-packages/electrum/plugins/coldcard/coldcard.py", line 233, in sign_transaction_poll
return self.dev.send_recv(CCProtocolPacker.get_signed_txn(), timeout=None)
File "/tmp/.mount_electrcFBIsQ/usr/lib/python3.7/site-packages/ckcc/client.py", line 139, in send_recv
buf = self.dev.read(64, timeout_ms=(timeout or 0))
File "hid.pyx", line 123, in hid.device.read
OSError: read error
double free or corruption (fasttop)
Aborted

# Fixed code
def __init__(self, *, plugin: "HW_PluginBase"):
    assert_runs_in_hwd_thread()
    self.plugin = plugin
# Buggy code
def close(self):
    with self.device_manager().hid_lock:
        self.dongleObject.dongle.close()


# Traceback (OSError)
$ ~/Downloads/apps/electrum-4.0.2-x86_64.AppImage --testnet
Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway.
E | plugin.DeviceMgr | failed to create client for bitbox02 at b'0001:0009:01': Exception('No BitBox02 detected')
E | plugins.coldcard.coldcard.Coldcard_KeyStore |
Traceback (most recent call last):
File "/tmp/.mount_electrcFBIsQ/usr/lib/python3.7/site-packages/electrum/plugins/coldcard/coldcard.py", line 383, in sign_transaction
resp = client.sign_transaction_poll()
File "/tmp/.mount_electrcFBIsQ/usr/lib/python3.7/site-packages/electrum/plugins/coldcard/coldcard.py", line 233, in sign_transaction_poll
return self.dev.send_recv(CCProtocolPacker.get_signed_txn(), timeout=None)
File "/tmp/.mount_electrcFBIsQ/usr/lib/python3.7/site-packages/ckcc/client.py", line 139, in send_recv
buf = self.dev.read(64, timeout_ms=(timeout or 0))
File "hid.pyx", line 123, in hid.device.read
OSError: read error
double free or corruption (fasttop)
Aborted

# Fixed code
def close(self):
    self.dongleObject.dongle.close()
# Buggy code
def get_btchip_device(self, device):
    ledger = False
    if device.product_key[0] == 0x2581 and device.product_key[1] == 0x3B7C:
        ledger = True
    if device.product_key[0] == 0x2581 and device.product_key[1] == 0x4B7C:
        ledger = True
    if device.product_key[0] == 0x2C97:
        if device.interface_number == 0 or device.usage_page == 0xFFA0:
            ledger = True
        else:
            return None  # non-compatible interface of a Nano S or Blue
    with self.device_manager().hid_lock:
        dev = hid.device()
        dev.open_path(device.path)
        dev.set_nonblocking(True)
    return HIDDongleHIDAPI(dev, ledger, BTCHIP_DEBUG)


# Traceback (OSError)
$ ~/Downloads/apps/electrum-4.0.2-x86_64.AppImage --testnet
Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway.
E | plugin.DeviceMgr | failed to create client for bitbox02 at b'0001:0009:01': Exception('No BitBox02 detected')
E | plugins.coldcard.coldcard.Coldcard_KeyStore |
Traceback (most recent call last):
File "/tmp/.mount_electrcFBIsQ/usr/lib/python3.7/site-packages/electrum/plugins/coldcard/coldcard.py", line 383, in sign_transaction
resp = client.sign_transaction_poll()
File "/tmp/.mount_electrcFBIsQ/usr/lib/python3.7/site-packages/electrum/plugins/coldcard/coldcard.py", line 233, in sign_transaction_poll
return self.dev.send_recv(CCProtocolPacker.get_signed_txn(), timeout=None)
File "/tmp/.mount_electrcFBIsQ/usr/lib/python3.7/site-packages/ckcc/client.py", line 139, in send_recv
buf = self.dev.read(64, timeout_ms=(timeout or 0))
File "hid.pyx", line 123, in hid.device.read
OSError: read error
double free or corruption (fasttop)
Aborted

# Fixed code
def get_btchip_device(self, device):
    ledger = False
    if device.product_key[0] == 0x2581 and device.product_key[1] == 0x3B7C:
        ledger = True
    if device.product_key[0] == 0x2581 and device.product_key[1] == 0x4B7C:
        ledger = True
    if device.product_key[0] == 0x2C97:
        if device.interface_number == 0 or device.usage_page == 0xFFA0:
            ledger = True
        else:
            return None  # non-compatible interface of a Nano S or Blue
    dev = hid.device()
    dev.open_path(device.path)
    dev.set_nonblocking(True)
    return HIDDongleHIDAPI(dev, ledger, BTCHIP_DEBUG)
# Buggy code
def __init__(self, d: StoredDict):
    super().__init__(d)
    self.force_watching_only = False
    self.ux_busy = False


# Traceback (TypeError)
E | gui.qt.exception_window.Exception_Hook | exception caught by crash reporter
Traceback (most recent call last):
File "...\electrum\electrum\gui\qt\main_window.py", line 2838, in closeEvent
self.clean_up()
File "...\electrum\electrum\gui\qt\main_window.py", line 2856, in clean_up
self.gui_object.close_window(self)
File "...\electrum\electrum\gui\qt\__init__.py", line 339, in close_window
self.daemon.stop_wallet(window.wallet.storage.path)
File "...\electrum\electrum\daemon.py", line 453, in stop_wallet
wallet.stop_threads()
File "...\electrum\electrum\wallet.py", line 314, in stop_threads
self.save_keystore()
File "...\electrum\electrum\wallet.py", line 1908, in save_keystore
self.db.put('keystore', self.keystore.dump())
File "...\electrum\electrum\json_db.py", line 38, in wrapper
return func(self, *args, **kwargs)
File "...\electrum\electrum\json_db.py", line 184, in put
self.data[key] = copy.deepcopy(value)
File "...\Python38\lib\copy.py", line 146, in deepcopy
y = copier(x, memo)
File "...\Python38\lib\copy.py", line 230, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "...\Python38\lib\copy.py", line 172, in deepcopy
y = _reconstruct(x, memo, *rv)
File "...\Python38\lib\copy.py", line 270, in _reconstruct
state = deepcopy(state, memo)
File "...\Python38\lib\copy.py", line 146, in deepcopy
y = copier(x, memo)
File "...\Python38\lib\copy.py", line 230, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "...\Python38\lib\copy.py", line 172, in deepcopy
y = _reconstruct(x, memo, *rv)
File "...\Python38\lib\copy.py", line 270, in _reconstruct
state = deepcopy(state, memo)
File "...\Python38\lib\copy.py", line 146, in deepcopy
y = copier(x, memo)
File "...\Python38\lib\copy.py", line 230, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "...\Python38\lib\copy.py", line 161, in deepcopy
rv = reductor(4)
TypeError: cannot pickle '_thread.RLock' object

# Fixed code
def __init__(self, d: dict):
    super().__init__(d)
    self.force_watching_only = False
    self.ux_busy = False
# Buggy code
def __init__(self, d):
    Hardware_KeyStore.__init__(self, d)
    # Errors and other user interaction is done through the wallet's
    # handler.  The handler is per-window and preserved across
    # device reconnects
    self.force_watching_only = False
    self.signing = False
    self.cfg = d.get("cfg", {"mode": 0})
    self.cfg = dict(self.cfg)  # convert to dict from StoredDict (see #6066)


# Traceback (TypeError)
E | gui.qt.exception_window.Exception_Hook | exception caught by crash reporter
Traceback (most recent call last):
File "...\electrum\electrum\gui\qt\main_window.py", line 2838, in closeEvent
self.clean_up()
File "...\electrum\electrum\gui\qt\main_window.py", line 2856, in clean_up
self.gui_object.close_window(self)
File "...\electrum\electrum\gui\qt\__init__.py", line 339, in close_window
self.daemon.stop_wallet(window.wallet.storage.path)
File "...\electrum\electrum\daemon.py", line 453, in stop_wallet
wallet.stop_threads()
File "...\electrum\electrum\wallet.py", line 314, in stop_threads
self.save_keystore()
File "...\electrum\electrum\wallet.py", line 1908, in save_keystore
self.db.put('keystore', self.keystore.dump())
File "...\electrum\electrum\json_db.py", line 38, in wrapper
return func(self, *args, **kwargs)
File "...\electrum\electrum\json_db.py", line 184, in put
self.data[key] = copy.deepcopy(value)
File "...\Python38\lib\copy.py", line 146, in deepcopy
y = copier(x, memo)
File "...\Python38\lib\copy.py", line 230, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "...\Python38\lib\copy.py", line 172, in deepcopy
y = _reconstruct(x, memo, *rv)
File "...\Python38\lib\copy.py", line 270, in _reconstruct
state = deepcopy(state, memo)
File "...\Python38\lib\copy.py", line 146, in deepcopy
y = copier(x, memo)
File "...\Python38\lib\copy.py", line 230, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "...\Python38\lib\copy.py", line 172, in deepcopy
y = _reconstruct(x, memo, *rv)
File "...\Python38\lib\copy.py", line 270, in _reconstruct
state = deepcopy(state, memo)
File "...\Python38\lib\copy.py", line 146, in deepcopy
y = copier(x, memo)
File "...\Python38\lib\copy.py", line 230, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "...\Python38\lib\copy.py", line 161, in deepcopy
rv = reductor(4)
TypeError: cannot pickle '_thread.RLock' object

# Fixed code
def __init__(self, d):
    Hardware_KeyStore.__init__(self, d)
    # Errors and other user interaction is done through the wallet's
    # handler.  The handler is per-window and preserved across
    # device reconnects
    self.force_watching_only = False
    self.signing = False
    self.cfg = d.get("cfg", {"mode": 0})
# Buggy code
def __init__(self, d):
    Hardware_KeyStore.__init__(self, d)
    # Errors and other user interaction is done through the wallet's
    # handler.  The handler is per-window and preserved across
    # device reconnects
    self.force_watching_only = False
    self.signing = False
    self.cfg = d.get("cfg", {"mode": 0})


# Traceback (TypeError)
E | gui.qt.exception_window.Exception_Hook | exception caught by crash reporter
Traceback (most recent call last):
File "...\electrum\electrum\gui\qt\main_window.py", line 2838, in closeEvent
self.clean_up()
File "...\electrum\electrum\gui\qt\main_window.py", line 2856, in clean_up
self.gui_object.close_window(self)
File "...\electrum\electrum\gui\qt\__init__.py", line 339, in close_window
self.daemon.stop_wallet(window.wallet.storage.path)
File "...\electrum\electrum\daemon.py", line 453, in stop_wallet
wallet.stop_threads()
File "...\electrum\electrum\wallet.py", line 314, in stop_threads
self.save_keystore()
File "...\electrum\electrum\wallet.py", line 1908, in save_keystore
self.db.put('keystore', self.keystore.dump())
File "...\electrum\electrum\json_db.py", line 38, in wrapper
return func(self, *args, **kwargs)
File "...\electrum\electrum\json_db.py", line 184, in put
self.data[key] = copy.deepcopy(value)
File "...\Python38\lib\copy.py", line 146, in deepcopy
y = copier(x, memo)
File "...\Python38\lib\copy.py", line 230, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "...\Python38\lib\copy.py", line 172, in deepcopy
y = _reconstruct(x, memo, *rv)
File "...\Python38\lib\copy.py", line 270, in _reconstruct
state = deepcopy(state, memo)
File "...\Python38\lib\copy.py", line 146, in deepcopy
y = copier(x, memo)
File "...\Python38\lib\copy.py", line 230, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "...\Python38\lib\copy.py", line 172, in deepcopy
y = _reconstruct(x, memo, *rv)
File "...\Python38\lib\copy.py", line 270, in _reconstruct
state = deepcopy(state, memo)
File "...\Python38\lib\copy.py", line 146, in deepcopy
y = copier(x, memo)
File "...\Python38\lib\copy.py", line 230, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "...\Python38\lib\copy.py", line 161, in deepcopy
rv = reductor(4)
TypeError: cannot pickle '_thread.RLock' object

# Fixed code
def __init__(self, d):
    Hardware_KeyStore.__init__(self, d)
    # Errors and other user interaction is done through the wallet's
    # handler.  The handler is per-window and preserved across
    # device reconnects
    self.force_watching_only = False
    self.signing = False
    self.cfg = d.get("cfg", {"mode": 0})
    self.cfg = dict(self.cfg)  # convert to dict from StoredDict (see #6066)