Why is it that the first code, where I call coroutine directly, crashes with an error, and the second, where I run it in a separate thread, executes without errors?
first:
scanner = ScannerInstrument(ccxtpro.mexc, Apis.Alex)
asyncio.run(scanner.scan())
second:
scanner = ScannerInstrument(ccxtpro.mexc, Apis.Alex)
def _main():
asyncio.run(scanner.scan())
Thread(target=_main).start()
Exception in callback <Task pending name='Task-1' coro=<QuantScannerCrossInstrument.scan() running at D:\_trade\robot\Trade_Dev\Robots\ScannerInstrument.py:64> cb=[_run_until_complete_cb() at C:\Users\suppo\AppData\Local\Programs\Python\Python313\Lib\asyncio\base_events.py:181]>()
handle: <Handle <Task pending name='Task-1' coro=<QuantScannerCrossInstrument.scan() running at D:\_trade\robot\Quant_Trade_Dev\QuantRobots\QuantScannerCrossInstrument.py:64> cb=[_run_until_complete_cb() at C:\Users\suppo\AppData\Local\Programs\Python\Python313\Lib\asyncio\base_events.py:181]>()>
Traceback (most recent call last):
File "C:\Users\suppo\AppData\Local\Programs\Python\Python313\Lib\asyncio\events.py", line 89, in _run
self._context.run(self._callback, *self._args)
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'Task' object is not callable