neonize
neonize copied to clipboard
How to add new client for async multisession
For async multisession, what is the best way to add the second and subsequent clients?
I used the ClientFactory.new_client(uuid) method, a new client was created, but there is no display to scan the QR code.
I would really appreciate if someone could give an example
thank you
Here is my code for adding a new WhatsApp account :
async def add_new_device(websocket: WebSocket):
await websocket.accept()
print(f"WebSocket opened for new registration")
async def qr_handler(client: NewAClient, qr_data: bytes):
print("QR code generated")
await websocket.send_text(qr_data.decode("utf-8"))
try:
client = client_factory.new_client(uuid=uuid.uuid4().hex[:5])
client.event.list_func = client_factory.event.list_func
client.event.qr(qr_handler)
print('client : ' + str(client.uuid))
await client.connect()
while True:
await websocket.receive_text()
except Exception as e:
# print(f"Error: {str(e)}")
await websocket.close(code=1011, reason=str(e))
await websocket.close()
finally:
await websocket.close()
print("WebSocket closed")
and this is the error that occurred during accessing the above function :
Exception ignored on calling ctypes callback function: <function Event.blocking.<locals>.block.<locals>.wrap_blocking at 0x00000266712E3560>
Traceback (most recent call last):
File "C:\WorkspaceV2\dev\django\wasapbot\venv\Lib\site-packages\neonize\aioze\events.py", line 162, in wrap_blocking
loop.run_until_complete(f(self.client))
File "C:\Users\myacc\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 653, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "C:\WorkspaceV2\dev\django\wasapbot\venv\Lib\site-packages\neonize\aioze\events.py", line 173, in default_blocking
await event.wait()
File "C:\Users\myacc\AppData\Local\Programs\Python\Python311\Lib\asyncio\locks.py", line 210, in wait
fut = self._get_loop().create_future()
^^^^^^^^^^^^^^^^
File "C:\Users\myacc\AppData\Local\Programs\Python\Python311\Lib\asyncio\mixins.py", line 20, in _get_loop
raise RuntimeError(f'{self!r} is bound to a different event loop')
RuntimeError: <asyncio.locks.Event object at 0x00000266711C2210 [unset, waiters:1]> is bound to a different event loop
Appreciate any help and thank you
Hmm, i haven't tussled with multi-client yet so I'm sorta clueless but what's going wrong here as to do with mixing different event loops