Skip to content

Instantly share code, notes, and snippets.

View davidkhess's full-sized avatar

David K. Hess davidkhess

View GitHub Profile
@davidkhess
davidkhess / happyeyeballs.py
Last active February 21, 2019 14:33
Happy Eyeballs solution using gevent modeled after Nathaniel J. Smith's canonical version for Trio
import gevent
import gevent.event
import gevent.socket
import gevent.pool
def open_tcp_socket(hostname, port, *, timeout=0.250):
targets = gevent.socket.getaddrinfo(hostname, port, type=gevent.socket.SOCK_STREAM)
result = gevent.event.AsyncResult()
group = gevent.pool.Group()