-
Notifications
You must be signed in to change notification settings - Fork 113
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
I used to debug backend-api by simple adding this:
if __name__ == "__main__":
import uvicorn
uvicorn.run(app=app, host="0.0.0.0", port=8000)
to the main.py, PyCharm allowed me to stop on break-points, evaluate expressions, etc.
But after update to v2.1.0, it fails with RuntimeError: no running event loop error:
Traceback (most recent call last):
File "<frozen importlib._bootstrap>", line 1078, in _handle_fromlist
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/Users/komposter/dev/emporus-hummingbot-backend-api/routers/manage_backtesting.py", line 12, in <module>
backtesting_engine = BacktestingEngineBase()
File "/Users/komposter/miniconda3/envs/backend-api/lib/python3.10/site-packages/hummingbot/strategy_v2/backtesting/backtesting_engine_base.py", line 36, in __init__
self.backtesting_data_provider = BacktestingDataProvider(connectors={})
File "/Users/komposter/miniconda3/envs/backend-api/lib/python3.10/site-packages/hummingbot/strategy_v2/backtesting/backtesting_data_provider.py", line 37, in __init__
self.connectors = {name: self.get_connector(name) for name, settings in self.conn_settings.items()
File "/Users/komposter/miniconda3/envs/backend-api/lib/python3.10/site-packages/hummingbot/strategy_v2/backtesting/backtesting_data_provider.py", line 37, in <dictcomp>
self.connectors = {name: self.get_connector(name) for name, settings in self.conn_settings.items()
File "/Users/komposter/miniconda3/envs/backend-api/lib/python3.10/site-packages/hummingbot/strategy_v2/backtesting/backtesting_data_provider.py", line 55, in get_connector
connector = connector_class(**init_params)
File "/Users/komposter/miniconda3/envs/backend-api/lib/python3.10/site-packages/hummingbot/connector/exchange/ndax/ndax_exchange.py", line 96, in __init__
self._shared_client = aiohttp.ClientSession()
File "/Users/komposter/miniconda3/envs/backend-api/lib/python3.10/site-packages/aiohttp/client.py", line 310, in __init__
loop = loop or asyncio.get_running_loop()
RuntimeError: no running event loop
It fails with the same error if I run it asynchronously:
if __name__ == "__main__":
import uvicorn
import asyncio
asyncio.run(uvicorn.run(app, host="127.0.0.1", port=8000, log_level="info"))
I've made it run by adding a return in the very beginning of the __init__ function of the /site-packages/hummingbot/connector/exchange/ndax/ndax_exchange.py.
But it still fails on requests from a dashboard:
INFO: 127.0.0.1:56876 - "GET /is-docker-running HTTP/1.1" 500 Internal Server Error
ERROR: Exception in ASGI application
Traceback (most recent call last):
File "/Users/komposter/miniconda3/envs/backend-api/lib/python3.10/site-packages/uvicorn/protocols/http/httptools_impl.py", line 409, in run_asgi
result = await app( # type: ignore[func-returns-value]
File "/Users/komposter/miniconda3/envs/backend-api/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 60, in __call__
return await self.app(scope, receive, send)
File "/Users/komposter/miniconda3/envs/backend-api/lib/python3.10/site-packages/fastapi/applications.py", line 1054, in __call__
await super().__call__(scope, receive, send)
File "/Users/komposter/miniconda3/envs/backend-api/lib/python3.10/site-packages/starlette/applications.py", line 113, in __call__
await self.middleware_stack(scope, receive, send)
File "/Users/komposter/miniconda3/envs/backend-api/lib/python3.10/site-packages/starlette/middleware/errors.py", line 187, in __call__
raise exc
File "/Users/komposter/miniconda3/envs/backend-api/lib/python3.10/site-packages/starlette/middleware/errors.py", line 165, in __call__
await self.app(scope, receive, _send)
File "/Users/komposter/miniconda3/envs/backend-api/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 62, in __call__
await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
File "/Users/komposter/miniconda3/envs/backend-api/lib/python3.10/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
raise exc
File "/Users/komposter/miniconda3/envs/backend-api/lib/python3.10/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
await app(scope, receive, sender)
File "/Users/komposter/miniconda3/envs/backend-api/lib/python3.10/site-packages/starlette/routing.py", line 715, in __call__
await self.middleware_stack(scope, receive, send)
File "/Users/komposter/miniconda3/envs/backend-api/lib/python3.10/site-packages/starlette/routing.py", line 735, in app
await route.handle(scope, receive, send)
File "/Users/komposter/miniconda3/envs/backend-api/lib/python3.10/site-packages/starlette/routing.py", line 288, in handle
await self.app(scope, receive, send)
File "/Users/komposter/miniconda3/envs/backend-api/lib/python3.10/site-packages/starlette/routing.py", line 76, in app
await wrap_app_handling_exceptions(app, request)(scope, receive, send)
File "/Users/komposter/miniconda3/envs/backend-api/lib/python3.10/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
raise exc
File "/Users/komposter/miniconda3/envs/backend-api/lib/python3.10/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
await app(scope, receive, sender)
File "/Users/komposter/miniconda3/envs/backend-api/lib/python3.10/site-packages/starlette/routing.py", line 73, in app
response = await f(request)
File "/Users/komposter/miniconda3/envs/backend-api/lib/python3.10/site-packages/fastapi/routing.py", line 291, in app
solved_result = await solve_dependencies(
File "/Users/komposter/miniconda3/envs/backend-api/lib/python3.10/site-packages/fastapi/dependencies/utils.py", line 640, in solve_dependencies
solved = await run_in_threadpool(call, **solved_result.values)
File "/Users/komposter/miniconda3/envs/backend-api/lib/python3.10/site-packages/starlette/concurrency.py", line 39, in run_in_threadpool
return await anyio.to_thread.run_sync(func, *args)
File "/Users/komposter/miniconda3/envs/backend-api/lib/python3.10/site-packages/anyio/to_thread.py", line 56, in run_sync
return await get_async_backend().run_sync_in_worker_thread(
File "/Users/komposter/miniconda3/envs/backend-api/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 2469, in run_sync_in_worker_thread
async with limiter or cls.current_default_thread_limiter():
File "/Users/komposter/miniconda3/envs/backend-api/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 1982, in __aenter__
await self.acquire()
File "/Users/komposter/miniconda3/envs/backend-api/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 2036, in acquire
return await self.acquire_on_behalf_of(current_task())
File "/Users/komposter/miniconda3/envs/backend-api/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 2039, in acquire_on_behalf_of
await AsyncIOBackend.checkpoint_if_cancelled()
File "/Users/komposter/miniconda3/envs/backend-api/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 2372, in checkpoint_if_cancelled
cancel_scope = _task_states[task].cancel_scope
File "/Users/komposter/miniconda3/envs/backend-api/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 686, in __getitem__
assert isinstance(key, asyncio.Task)
AssertionError
What could be a solution? How to debug it now?
Steps to reproduce bug
- Download and install backend-api v2.1.0
- Add this to the main.py:
if __name__ == "__main__":
import uvicorn
uvicorn.run(app=app, host="0.0.0.0", port=8000)
- Try to run/debug in PyCharm.
Thanks for your great job!
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working