Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuntimeError with aiohttp #249

Closed
alexreznikoff opened this issue Feb 3, 2023 · 2 comments
Closed

RuntimeError with aiohttp #249

alexreznikoff opened this issue Feb 3, 2023 · 2 comments

Comments

@alexreznikoff
Copy link

My test application uses:

  • python = 3.10.9
  • aiohttp = 3.8.3
  • panini = 0.8.0

Code:

from aiohttp import web
from panini import app as panini_app
import sentry_sdk
import settings

app = panini_app.App(
    service_name='nats-microservice-that-also-http',
    host='127.0.0.1',
    port=4222,
)
app.setup_web_server(port=5000)


@app.listen("some.subject")
async def stream_listener(msg):
    print(f"event {msg.data} from {msg.subject} has been processed")


@app.http.get("/status")
async def web_endpoint_listener(request):
    return web.json_response({"status": "ok"})


if __name__ == "__main__":
    sentry_sdk.init(settings.SENTRY_SDK)
    app.start()

aiohttp GET /status endpoint responds correctly, but a runtime error is sent to the sentry on every request:
RuntimeError("Event loop stopped before Future completed.")

@artas728
Copy link
Collaborator

artas728 commented Feb 3, 2023

Hello @alexreznikoff
The problem is in the conflict related to sentry behavior (I have not worked with sentry before and do not know how it works). I ran your code without sentry and it works well. I would recommend trying to run sentry as a panini task:

from aiohttp import web
from panini import app as panini_app
import sentry_sdk
import settings

app = panini_app.App(
    service_name='nats-microservice-that-also-http',
    host='127.0.0.1',
    port=4222,
)
app.setup_web_server(port=5000)

@app.task()
def start_sentry():
    sentry_sdk.init(settings.SENTRY_SDK)

@app.listen("some.subject")
async def stream_listener(msg):
    print(f"event {msg.data} from {msg.subject} has been processed")


@app.http.get("/status")
async def web_endpoint_listener(request):
    return web.json_response({"status": "ok"})

if __name__ == "__main__":
    app.start()

Let me know if it works.

@alexreznikoff
Copy link
Author

Hello @artas728
Thank you, it works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants