SlideShare ist ein Scribd-Unternehmen logo
1 von 33
Downloaden Sie, um offline zu lesen
Twisted Logic
     PyCon 2013


         -   Ashwini Oruganti
                  @_ashfall_
Twisted
asynchronous event-driven
  networking framework
Twisted
asynchronous event-driven
  networking framework

      aka... HARD
Google Summer of Code
 spend the summer working on
 an open source project with a
    mentoring organization
Endpoint
an interface with a single method that
          takes an argument
                      *
               returns :
a listening port / a connected protocol
Server
 endpoint = TCP4ServerEndpoint(reactor, 8007)
 endpoint.listen(Factory())



Client
 endpoint = TCP4ClientEndpoint(reactor,
                       "localhost", 8007)
 endpoint.connect(Factory())
class TCP4ServerEndpoint(object):
    """
    Implements TCP server endpoint with an IPv4
    configuration
    """
    ...
    def __init__(self, reactor, port,
                 backlog=50, interface=''):
        ...

    def listen(self, protocolFactory):
        return defer.execute(
                        self._reactor.listenTCP,
                        ...)
class TCP6ServerEndpoint(object):
    """
    Implements TCP server endpoint with an IPv6
    configuration
    """
    ...
    def __init__(self, reactor, port,
                  backlog=50, interface='::'):
        ...

    def listen(self, protocolFactory):
        return defer.execute(
                         self._reactor.listenTCP,
                        ...)
It’s just code.
class StandardIOEndpoint(object):
    """
    A Standard Input/Output endpoint
    """
    implements(interfaces.IStreamServerEndpoint)

    def __init__(self, reactor):
        ...

    def listen(self, stdioProtocolFactory):
        return defer.execute(stdio.StandardIO,
            stdioProtocolFactory.buildProtocol(
                PipeAddress()))
Moral of the story:
Do not get flustered.
 Do not overthink..
 Forget it's Twisted
Moral of the story:
   Read the code.
 Solve the problem
    (write code)
There’s nothing more
       boring
      than the
    comfort zone
TCP Client Endpoint
    IPv6 addresses
  Hostname Resolution
class TCP6ClientEndpoint(object):
   def __init__(self, reactor, host, port,
               timeout=30, bindAddress=None):
       ...


  def connect(self, protocolFactory):
      """
      Connect via TCP, once the hostname
      resolution is done.
      """
      ...
def _nameResolution(self, host):
    """
    Resolve the hostname string into a tuple
    containing the host IPv6 address.
    """
    ...

def _resolvedHostConnect(self, resolvedHost,
                         protocolFactory):
    """
    Connect to the server using the resolved
    hostname.
    """
    ...
Deferred
Callbacks and Errbacks
 Flow is not obvious
 Debugging is tricky
class SomeState(object):
    def __init__(self):
        self.values = []

    def getValue(self):
        return self.values.pop(0)

    def addValue(self, value):
        self.values.append(value)
def foo():
   return SomeState()

def bar():
    state = foo()
    print state.getValue()
Firing the Deferred
  def foo():
      s = SomeState()
      s.addValue(2)
      return s
It’s just code.
It’s 'X', when it isn't
      really 'X'
It’s full of highly
complex concepts!
“It was created by a couple of
  dudes who dropped out of
  school, and a 16-year-old.

  HOW HARD COULD IT BE?”
It’s foreign!
camelCase
 PEP8: July 5, 2001
   Twisted’s coding
standard: May 2, 2001
It’s huge!
“Core can fit into a floppy
          disk.”
Know what you're
     doing.
<conclusion />

Weitere ähnliche Inhalte

Was ist angesagt?

Gevent what's the point
Gevent what's the pointGevent what's the point
Gevent what's the point
seanmcq
 

Was ist angesagt? (20)

Gevent what's the point
Gevent what's the pointGevent what's the point
Gevent what's the point
 
Async programming and python
Async programming and pythonAsync programming and python
Async programming and python
 
Netty: asynchronous data transfer
Netty: asynchronous data transferNetty: asynchronous data transfer
Netty: asynchronous data transfer
 
Python meetup: coroutines, event loops, and non-blocking I/O
Python meetup: coroutines, event loops, and non-blocking I/OPython meetup: coroutines, event loops, and non-blocking I/O
Python meetup: coroutines, event loops, and non-blocking I/O
 
swift-nio のアーキテクチャーと RxHttpClient
swift-nio のアーキテクチャーと RxHttpClientswift-nio のアーキテクチャーと RxHttpClient
swift-nio のアーキテクチャーと RxHttpClient
 
Socket System Calls
Socket System CallsSocket System Calls
Socket System Calls
 
Opentalk at Large - StS 2005
Opentalk at Large - StS 2005Opentalk at Large - StS 2005
Opentalk at Large - StS 2005
 
LibreSSL, one year later
LibreSSL, one year laterLibreSSL, one year later
LibreSSL, one year later
 
Socket programming
Socket programmingSocket programming
Socket programming
 
Silicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM MechanicsSilicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM Mechanics
 
JAVA NIO
JAVA NIOJAVA NIO
JAVA NIO
 
Whispered secrets
Whispered secretsWhispered secrets
Whispered secrets
 
Penetration testing using python
Penetration testing using pythonPenetration testing using python
Penetration testing using python
 
PHP7 is coming
PHP7 is comingPHP7 is coming
PHP7 is coming
 
TensorFlow XLA RPC
TensorFlow XLA RPCTensorFlow XLA RPC
TensorFlow XLA RPC
 
Jan Stępień - GraalVM: Fast, Polyglot, Native - Codemotion Berlin 2018
Jan Stępień - GraalVM: Fast, Polyglot, Native - Codemotion Berlin 2018Jan Stępień - GraalVM: Fast, Polyglot, Native - Codemotion Berlin 2018
Jan Stępień - GraalVM: Fast, Polyglot, Native - Codemotion Berlin 2018
 
Python for Penetration testers
Python for Penetration testersPython for Penetration testers
Python for Penetration testers
 
Socket Programming
Socket ProgrammingSocket Programming
Socket Programming
 
network programing lab file ,
network programing lab file ,network programing lab file ,
network programing lab file ,
 
08 - Return Oriented Programming, the chosen one
08 - Return Oriented Programming, the chosen one08 - Return Oriented Programming, the chosen one
08 - Return Oriented Programming, the chosen one
 

Ähnlich wie Twisted logic

Python concurrency: libraries overview
Python concurrency: libraries overviewPython concurrency: libraries overview
Python concurrency: libraries overview
Andrii Mishkovskyi
 

Ähnlich wie Twisted logic (20)

Introduction to clojure
Introduction to clojureIntroduction to clojure
Introduction to clojure
 
JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?
 
Python concurrency: libraries overview
Python concurrency: libraries overviewPython concurrency: libraries overview
Python concurrency: libraries overview
 
Python, do you even async?
Python, do you even async?Python, do you even async?
Python, do you even async?
 
How to Leverage Go for Your Networking Needs
How to Leverage Go for Your Networking NeedsHow to Leverage Go for Your Networking Needs
How to Leverage Go for Your Networking Needs
 
Node.js - As a networking tool
Node.js - As a networking toolNode.js - As a networking tool
Node.js - As a networking tool
 
Apache Thrift
Apache ThriftApache Thrift
Apache Thrift
 
java sockets
 java sockets java sockets
java sockets
 
Jenkins' shared libraries in action
Jenkins' shared libraries in actionJenkins' shared libraries in action
Jenkins' shared libraries in action
 
Node.js - async for the rest of us.
Node.js - async for the rest of us.Node.js - async for the rest of us.
Node.js - async for the rest of us.
 
Non Blocking I/O for Everyone with RxJava
Non Blocking I/O for Everyone with RxJavaNon Blocking I/O for Everyone with RxJava
Non Blocking I/O for Everyone with RxJava
 
Patterns for JVM languages JokerConf
Patterns for JVM languages JokerConfPatterns for JVM languages JokerConf
Patterns for JVM languages JokerConf
 
分散式系統
分散式系統分散式系統
分散式系統
 
node.js: Javascript's in your backend
node.js: Javascript's in your backendnode.js: Javascript's in your backend
node.js: Javascript's in your backend
 
Apache Beam de A à Z
 Apache Beam de A à Z Apache Beam de A à Z
Apache Beam de A à Z
 
C++aptitude questions and answers
C++aptitude questions and answersC++aptitude questions and answers
C++aptitude questions and answers
 
Coroutines for Kotlin Multiplatform in Practise
Coroutines for Kotlin Multiplatform in PractiseCoroutines for Kotlin Multiplatform in Practise
Coroutines for Kotlin Multiplatform in Practise
 
Node intro
Node introNode intro
Node intro
 
srgoc
srgocsrgoc
srgoc
 
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
 

Kürzlich hochgeladen

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Kürzlich hochgeladen (20)

WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 

Twisted logic