Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def open(self):
"""
Finish context initialisation, as is normally done in __enter__ .
This happens automatically on the first method call needing access to
the uninitialised properties, but with a warning.
Call this method ONLY if your usage pattern prevents you from using the
with USBContext() as contewt:
form: this means there are ways to avoid calling close(), which can
cause issues particularly hard to debug (ex: interpreter hangs on
exit).
"""
assert self.__context_refcount == 0
mayRaiseUSBError(libusb1.libusb_init(byref(self.__context_p)))
return self
def __init__(self):
"""
Create a new USB context.
"""
context_p = libusb1.libusb_context_p()
result = libusb1.libusb_init(byref(context_p))
if result:
raise libusb1.USBError(result)
self.__context_p = context_p
def __init__(self):
"""
Create a new USB context.
"""
# Used to prevent an exit to cause a segfault if a concurrent thread
# is still in libusb.
self.__context_refcount = 0
self.__context_cond = threading.Condition()
context_p = libusb1.libusb_context_p()
result = libusb1.libusb_init(byref(context_p))
if result:
raise libusb1.USBError(result)
self.__context_p = context_p