apscheduler: ASGI Middleware example doesn't work in 4.0.0a

Things to check first

  • I have checked that my issue does not already have a solution in the FAQ

  • I have searched the existing issues and didn’t find my bug already reported there

  • I have checked that my bug is still present in the latest release

Version

4.0.0a2

What happened?

Hello, I am trying to adapt your example to create a middleware for an ASGI framework I’m using called Starlite, which based on their docs, seems straightforward. But as far as I can tell, the scheduler isn’t getting started, I never see the tick() function get called and nothing prints.

So I tried running the example provided for Starlette (v0.21.0). The tick() never prints for Starlette, and I get the following printed out in the log:

INFO: ASGI 'lifespan' protocol appears unsupported. (I only get this for Starlette, not Starlite)

I understand APScheduler v4 is still an alpha release, so I wanted to see if this is a known issue, or if there’s a workaround I could try.

Cheers

How can we reproduce the bug?

Running the exact code provided in the example should reproduce the issue.

https://github.com/agronholm/apscheduler/blob/master/examples/web/asgi_starlette.py

I’m using Python 3.11 and Starlette 0.21.0.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 16 (9 by maintainers)

Most upvoted comments

Even better if you have access to whatever exception triggered the shutdown (pass that to __aexit__() as type, value, value.__traceback__).

Create the exit stack somewhere, then call await exit_stack.__aenter__() in on_startup and await exit_stack.__aexit__(None, None, None) in on_shutdown(). In on_startup(), you can then activate the scheduler by await exit_stack.enter_async_context(scheduler).