$30 off During Our Annual Pro Sale. View Details »

Asynchronous Event-driven Architecture - The Twisted Way

Asynchronous Event-driven Architecture - The Twisted Way

This talk is aimed at explaining the event-driven architecture and asynchronous model, the reactor-pattern, and the basic concepts that make understanding and writing Twisted programs easier, and less abstruse and esoteric.

Picking up clues from the numerous attempts in the past to demystify the popular beliefs about the occult nature of Twisted, the talk is designed to help you acquire the “mental model” required to write and comprehend asynchronous code. We will start by developing a basic understanding of the synchronous, threaded, and asynchronous models, then move on to comparing and contrasting the former two with the latter.

Further, we will try and understand the philosophy and motivation behind the asynchronous event-driven model, and discuss the Twisted reactor and event-loop architecture. Finally, we'll try to contemplate and demystify "The Twisted Way" of doing things bolstered by excerpts from Tao Te Ching and The Tao of Programming.

Ashwini Oruganti

October 13, 2013

More Decks by Ashwini Oruganti

Other Decks in Programming


  1. The Twisted Way - Ashwini Oruganti @_ashfall_ PyCon Ireland 2013

  2. Twisted asynchronous event-driven networking framework

  3. Twisted asynchronous event-driven networking framework aka... HARD

  4. The Need Twisted Reality: The Game Threads and Java The

  5. The Beginning select() asyncore and Medusa …

  6. The Beginning Medusa: Unmaintained and direct socket manipulation …

  7. The Beginning … Twisted

  8. Programming Models Single-threaded Multi-threaded Asynchronous

  9. Single-threaded time

  10. Single-threaded <limitations>

  11. Multi-threaded time

  12. Multi-threaded <limitations>

  13. Event-driven time

  14. Event-driven <advantages>

  15. The Reactor Waits on and handles events abstracts away platform-

    specific behavior
  16. Event-loop while True: timeout = time_until_next_timed_event() events = wait_for_events(timeout) events

    += timed_events_until(now()) for event in events: event.process()
  17. “Twisted softens your brains and makes you feel like your

    head is actually a blender optimized for gray gloop.”
  18. “It was created by a couple of dudes who dropped

    out of school, and a 16-year-old. HOW HARD COULD IT BE?”
  19. The Box Metaphor

  20. “How do I even get this thing to do anything?”

  21. When you look for it, there is nothing to see.

    When you listen for it, there is nothing to hear. When you use it, it is inexhaustible.
  22. from twisted.internet import reactor reactor.run() The World’s Largest NOP

  23. “The Master does his job and then stops. He understands

    that the universe is forever out of control.”
  24. It’s humongous!

  25. “Core can fit into a floppy disk.”

  26. It’s just code.

  27. Know what you're doing.

  28. None
  29. <questions/>