[Python] deepcopy error

깨미·2022년 6월 10일
0

Python

목록 보기
9/10
post-thumbnail

TypeError: cannot pickle '_bleak_winrt_Windows_Devices_Bluetooth_GenericAttributeProfile.GattDeviceService' object

python 에서 Bleak 모듈을 사용하여 BLE APP을 짜던 중 BleakClient Class를 담은 list를 deepcopy 하니 발생한 에러.
사용하고 있는 BleakClient 때문인거 같아 deepcopy는 사용할 수 없다고 판단했다. 그래서 list 자체의 copy를 사용하기로 했다 !

Error Code

async def ble_connect(self, address):
        self.connected_client.append(BleakClient(address)) # 여기서 list 추가
        client = self.connected_client[len(self.connected_client)-1]
        try:
            await client.connect()
        except Exception as e:
            print('[ERR] : ', e) 
            
async def ble_all_disconnect(self):
        temp_list = copy.deepcopy(self.connected_client) # 에러 발생
        for i in range(len(temp_list)) :
            await temp_list[i].disconnect()

Edit Code

    async def ble_all_disconnect(self):
        temp_list = self.connected_client.copy() # 여기를 list의 copy 이용
        for i in range(len(temp_list)) :
            await temp_list[i].disconnect()

더 나아가서

나중에는 직접 deepcopy class를 만드는 걸 고려해 봐야 겠다.

profile
vis ta vie

0개의 댓글