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

on_start and on_shutdown not work #153

Open
shaohaiyang opened this issue Jan 11, 2024 · 4 comments
Open

on_start and on_shutdown not work #153

shaohaiyang opened this issue Jan 11, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@shaohaiyang
Copy link

Describe the bug
The code can work, but on_start and on_shutdown not running

@eirnym
Copy link

eirnym commented Jan 11, 2024

Could you please inline code here?

@shaohaiyang
Copy link
Author

from socketify import App
import asyncio 
app = App(lifespan=False)
router = app.router()

@app.on_start
async def on_start():
    print("wait...")
    await asyncio.sleep(1)
    print("start!")

@app.on_shutdown
async def on_shutdown():
    print("wait...")
    await asyncio.sleep(1)
    print("shutdown!")

@router.get("/")
def home(res, req, data=None):
    res.send({"Hello": "World!"}, headers=(("X-Rate-Limit-Remaining", "10"), (b'Another-Headers', b'Value')))


app.listen(
    3000,
    lambda config: print("Listening on port http://localhost:%d now\n" % config.port),
)
app.run()

the startup function on_start() don't print wait... and start! words

@shaohaiyang
Copy link
Author

from socketify import App
import asyncio

def run(app: App):

    @app.on_start
    async def on_start():
        print("wait...")
        await asyncio.sleep(1)
        print("start!")

    @app.on_shutdown
    async def on_shutdown():
        print("wait...")
        await asyncio.sleep(1)
        print("shutdown!")

    router = app.router()

    @router.get("/")
    def home(res, req):
        res.send("Hello, World!")

when i running above code , the display the ERROR as below:

pypy3 -m socketify xx:run --host 0.0.0.0 --port 8080
wait...
ERROR:root:Uncaught Exception: no running event loop
Listening on http://0.0.0.0:8080 now

@cirospaciari
Copy link
Owner

Thanks for reporting, I probably break this trying to fix lifespan, I really need to push more fixes and CI/CD tests

@cirospaciari cirospaciari added the bug Something isn't working label Jan 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants