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

Fix "DeprecationWarning: There is no current event loop" #2390

Merged
merged 3 commits into from
Mar 30, 2022
Merged

Fix "DeprecationWarning: There is no current event loop" #2390

merged 3 commits into from
Mar 30, 2022

Conversation

jmarcet
Copy link
Contributor

@jmarcet jmarcet commented Jan 24, 2022

I'm seeing the warning on Windows platforms only but it is a general deprecation of Python 3.10, to be dropped for 3.11

Signed-off-by: Javier Marcet <javier@marcet.info>
@jmarcet jmarcet requested a review from a team as a code owner January 24, 2022 15:23
@ahopkins
Copy link
Member

Thanks for the contribution. Can you let me know the context in which you are seeing this? I am particularly interested to know what is calling this causing the notice.

What platform are you seeing this on? OS/Python/Sanic?

@jmarcet
Copy link
Contributor Author

jmarcet commented Jan 24, 2022

I am seeing this when running my iptv proxy movistar-u7d natively on Windows.

I am using python 3.10, installed with scoop on Windows 11 x86_64 and sanic stable, i.e., v21.12.1

For some reason I'm also getting a [WARNING] Sanic is running in PRODUCTION mode. Consider using '--debug' or '--dev' while actively developing your application. in the same environment. None of that happens in Linux.

The proxy has two sanic backends, which start here and here

By the way, having Sanic running as native Windows applications, compiled with cx_Freeze is a real breeze 😄

@ahopkins
Copy link
Member

ahopkins commented Jan 25, 2022

For some reason I'm also getting a [WARNING] Sanic is running in PRODUCTION mode. Consider using '--debug' or '--dev' while actively developing your application. in the same environment. None of that happens in Linux.

This shows up on in TTY output when debug is off.


So, if you are not calling app.loop manually, then something is outside of a running loop. While this may "solve" the problem, it seems more like a bandaid.

@jmarcet
Copy link
Contributor Author

jmarcet commented Jan 25, 2022

This shows up on in TTY output when debug is off.

Yeah, I checked it after writing the message. I am not seeing it in Linux in general because I usually run under docker, not in a terminal directly.

So, if you are not calling app.loop manually, then something is outside of a running loop. While this may "solve" the problem, it seems more like a bandaid.

It is just app.run.

In those backends I only create tasks with asyncio.create_task() or launch external processes with asyncio.create_task() or app.add_task(). Now that I've checked, there is a reference to self.loop here, but the warning shows up in both backends, so that cannot be it.

Furthermore, it is Windows only, I never saw it in Linux.

@jmarcet
Copy link
Contributor Author

jmarcet commented Jan 25, 2022

I've just done a quick test with this simplistic sanic app:

#!/usr/bin/env python3

import sys

from sanic import Sanic, response
from sanic.log import logger as log


app = Sanic("test")


@app.get("/favicon.ico")
async def handle_favicon(request):
    return response.empty(200)


if __name__ == "__main__":
    try:
        app.run(
            host="127.0.0.1",
            port=9090,
            access_log=True,
            auto_reload=True,
            debug=True,
            workers=1,
        )
    except (KeyboardInterrupt, TimeoutError):
        sys.exit(1)
    except Exception as ex:
        log.critical(f"{repr(ex)}")
        sys.exit(1)

That's enough to trigger the warning:

image

@codecov
Copy link

codecov bot commented Mar 30, 2022

Codecov Report

Merging #2390 (7384047) into main (0cb342a) will increase coverage by 0.059%.
The diff coverage is 100.000%.

@@              Coverage Diff              @@
##              main     #2390       +/-   ##
=============================================
+ Coverage   87.242%   87.301%   +0.059%     
=============================================
  Files           60        60               
  Lines         5040      5040               
  Branches       907       907               
=============================================
+ Hits          4397      4400        +3     
+ Misses         472       470        -2     
+ Partials       171       170        -1     
Impacted Files Coverage Δ
sanic/app.py 89.230% <100.000%> (ø)
sanic/server/protocols/http_protocol.py 88.095% <0.000%> (+3.571%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0cb342a...7384047. Read the comment docs.

@ahopkins ahopkins merged commit bb44748 into sanic-org:main Mar 30, 2022
ChihweiLHBird pushed a commit to ChihweiLHBird/sanic that referenced this pull request Jun 1, 2022
)

Co-authored-by: Adam Hopkins <adam@amhopkins.com>
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

Successfully merging this pull request may close these issues.

2 participants