code: def patch_network_latency(seconds=0.01):
      
  
      # Accept float(0.1), "0.1", "0.1-0.2"
      def sleep():
          if isinstance(seconds, float):
              time.sleep(seconds)
          elif isinstance(seconds, basestring):
              # pylint: disable=maybe-no-member
              if "-" in seconds:
                  time.sleep(random.uniform(
                      float(seconds.split("-")[0]),
                      float(seconds.split("-")[1])
                  ))
              else:
                  time.sleep(float(seconds))
  
      def _patched_method(old_method, *args, **kwargs):
          sleep()
          return old_method(*args, **kwargs)
  
      socket_methods = [
          "send", "sendall", "sendto", "recv", "recvfrom", "recvfrom_into", "recv_into",
          "connect", "connect_ex", "close"
      ]
  
      from socket import socket as _socketmodule
      from gevent.socket import socket as _geventmodule
      from gevent.ssl import SSLSocket as _sslmodule   # pylint: disable=no-name-in-module
  
      for method in socket_methods:
          patch_method(_socketmodule, method, _patched_method)
          patch_method(_geventmodule, method, _patched_method)
          patch_method(_sslmodule, method, _patched_method)
docs: Add random latency to all I/O operations