Derek Chiang
Derek Chiang

Reputation: 3410

Simulate a hung client in Python

What's the easiest way to write a Python HTTP client that sends GET requests but refuses to read the response, just as if it's hung? The solution could involve using third-party libraries like requests.

Upvotes: 1

Views: 87

Answers (1)

VooDooNOFX
VooDooNOFX

Reputation: 4762

Sounds fishy. Why would you need to ignore a response unless you're trying to ddos a site. If you're trying to achieve some async goals, you need to go about this another way.

Otherwise, here's a socket solution (from effbot):

import socket
s = socket.socket()
s.connect(("www.python.org", 80))
s.send("GET / HTTP/1.0\r\n\r\n")
# s.recv(20) # Normally, we would call read, so skip this part completely
s.close()  # Still close the socket on your end though when you're ready.

Upvotes: 1

Related Questions