josh, (edited )
@josh@joshthomas.dev avatar

What’s your typical async application look like in Django? I’m starting to dip my toes in after primarily just working sync and am running in to brick wall after brick wall.

I’ve got a “toolbox” app at work with a few small Django apps to help out our small department in various things and wanted to async something to deal with GitHub webhooks. Using Django 5.0 and daphne.

josh,
@josh@joshthomas.dev avatar

First brick wall, django-debug-toolbar doesn’t async. Second, whitenoise.

Do people typically run sync and async in parallel processes on different ports?

CodenameTim,
@CodenameTim@fosstodon.org avatar

@josh we're hoping to close that gap this summer with a GSoC project.

josh,
@josh@joshthomas.dev avatar

@CodenameTim I hope you didn’t take that as a dig or complaint on the invaluable work y’all do

josh,
@josh@joshthomas.dev avatar

@CodenameTim mostly just speaking out loud about trying something out I don’t normally do

CodenameTim,
@CodenameTim@fosstodon.org avatar

@josh no, definitely not. You're voicing the reason we've been trying to implement it for the past few years. I'm excited to see how much of it we can achieve.

I'm a bit worried about how we instrument SSE or other responses that aren't tied to an explicit request. But we'll figure something out!

josh, (edited )
@josh@joshthomas.dev avatar

Any good blogs or docs about real world Django async usage? My searching is mostly coming up empty with beginner tuts about the initial setup, which I got down.

josh,
@josh@joshthomas.dev avatar

Doesn’t even have to be prose, some example source code I could work with

josh,
@josh@joshthomas.dev avatar

django-allauth no async too?

carlton,
@carlton@fosstodon.org avatar

@josh Yes, this. Run your main app with WSGI, as you always did. Then run a little sidecar, handling all your ASGI bits, for where you actually need async: long-lived connections, realtime updates, two-way comms.

You can do the whole app as ASGI but WSGI scaling patterns are super well known, and all the edge cases have been dealt with over the years.

romanroe,

@carlton @josh Would this "ASGI sidecar" be a different Django project with e.g. a different INSTALLED_APPS configuration (e.g. only async-compatible apps)? Do you know any articles or example projects?

carlton,
@carlton@fosstodon.org avatar

@romanroe @josh not normally I’d say. (Like you can do all that if you need to, but likely you don’t.) Literally you’re just serving an asgi.py instead of a wsgi.py.

Your asgi app maybe has Channels bits. Maybe has a different URLConf, to only serve the URLs you want. Maybe different middleware…

BUT your reverse proxy has to decide which requests to route where, so likely you don’t need to be too clever.

romanroe,

@carlton @josh Thanks alot!

josh,
@josh@joshthomas.dev avatar

@carlton Thanks Carlton 🙌

One of those moments as a self-taught programmer where something comes to you as the simple solution but you're not totally sure it's the CORRECT and BEST way to do something. Even as I add notches to my belt as the years go on, still hard to shake that feeling sometimes.

carlton,
@carlton@fosstodon.org avatar

@josh Glad to be of service 🎁

josh,
@josh@joshthomas.dev avatar

@carlton Side note, I'm not sure why the phrase 'notches in the belt' came to my head to refer to experience or where I've ever heard it before, but I liked the way it sounded. 😄 Looking up the source of the idiom, I found this quora post with one possible source - "A notch in one’s belt is an expression from the U.S. Old West that refers to counting the number of people one has killed." Morbid!

https://www.quora.com/What-is-another-idiom-for-a-notch-in-your-belt

carlton,
@carlton@fosstodon.org avatar

@josh Yeah, basically every utterance unwittingly carries with it an abominable history.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • DreamBathrooms
  • mdbf
  • osvaldo12
  • magazineikmin
  • GTA5RPClips
  • rosin
  • everett
  • Youngstown
  • Durango
  • slotface
  • khanakhh
  • kavyap
  • InstantRegret
  • thenastyranch
  • megavids
  • ethstaker
  • modclub
  • cisconetworking
  • anitta
  • cubers
  • tester
  • ngwrru68w68
  • tacticalgear
  • normalnudes
  • provamag3
  • Leos
  • JUstTest
  • lostlight
  • All magazines