~/talk

How To Break Django: With Async

Talkat DjangoCon Europe 2020 Β· 2020-09-18..09-19Β· [concurrency, django]
slides:none on file

Django 3.1 accepts async def views but database and many libraries remain synchronous so calling ORM code from async raises a SynchronousOnlyOperation error and blocks the event loop if misused. Use sync_to_async to run DB work in a worker thread but beware transactions and connection objects are threadbound so prior code can silently corrupt data. Python’s asyncio debug flags long-running coroutines and forgotten awaits. Recommended workflow is sync first, profile, then convert hot paths to async.

AI-written summary Β· about

  1. 0:00Intro
  2. 2:17Synchronous programming is quite safe
  3. 2:47Async programming is hard But it can definitely be worth it!
  4. 6:44SynchronousOnlyOperation: You cannot call this from an async context - use a thread or sync_to_async
  5. 8:33Django's got your back ..this time, anyway.
  6. 9:47There's no ordering guarantee! Or even a guarantee it will execute.
  7. 10:46await create_user_account() await send_created_email()
  8. 11:48Race conditions! Names are power - now you can research it!
  9. 13:22await verify_valid_user(...) await create_user_account(...)
  10. 15:39You don't actually have a transaction. We need to address this when we make the ORM async-aware!
  11. 18:54Bad with threads. Good with async! The await model brings us atomic sections for free
  12. 24:42How do we defend against these? Seems awfully easy to slip up, doesn't it.
  13. 27:19SynchronousOnlyOperation Django's here to save you from the worst errors, where we can
  14. 27:56Again, async programming is hard This is not just Python!
  15. 29:05you can quickly & safely add async.
  16. 29:49We'll get better patterns! Until then, be safe out there
~/search
type to search 8,222 conferences, 162,397 speakers and 219,688 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark β€” the status bar button does the same
← β†’
on a talk: 5 seconds back / forward
0–9
on a talk: jump to 0%–90% of the recording
?
this help
esc
close this, then clear every filter β€” or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.