question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ASGI Middleware example doesn't work in 4.0.0a

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:16 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
agronholmcommented, Oct 27, 2022

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

1reaction
agronholmcommented, Oct 27, 2022

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).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Improve Documentation on Writing Custom ASGI Middleware ...
Instructions on how to write custom ASGI Middleware with example code (can be based on an example from the codebase).
Read more >
Problem with ASGI lifespan when i use custom middleware
ASGI 'lifespan' protocol appears unsupported. enter image description here. Locally, the application works fine, but as soon as it is assembled ...
Read more >
Advanced Middleware - FastAPI
A middleware doesn't have to be made for FastAPI or Starlette to work, as long as it follows the ASGI spec. In general,...
Read more >
ASGI (Asynchronous Server Gateway Interface) Specification
This base specification is intended to fix in place the set of APIs by which these servers interact and run application code; each...
Read more >
Changelog — Datasette documentation
ASGI is the Asynchronous Server Gateway Interface standard. I've been wanting to convert Datasette into an ASGI application for over a year -...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found