Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9173069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:30:11+00:00 2026-06-17T16:30:11+00:00

I need to disable nagle algorithm in python2.6. I found out that patching HTTPConnection

  • 0

I need to disable nagle algorithm in python2.6.
I found out that patching HTTPConnection in httplib.py that way

    def connect(self):
        """Connect to the host and port specified in __init__."""
        self.sock = socket.create_connection((self.host,self.port),
                                         self.timeout)
        self.sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, True) # added line

does the trick.

Obviously, I would like to avoid patching system lib if possible. So, the question is: what is right way to do such thing? (I’m pretty new to python and can be easily missing some obvious solution here)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T16:30:13+00:00Added an answer on June 17, 2026 at 4:30 pm

    It’s not possible to change the socket options that httplib specifies, and it’s not possible to pass in your own socket object either. In my opinion this sort of lack of flexibility is the biggest weakness of most of the Python HTTP libraries. For example, prior to Python 2.6 it wasn’t even possible to specify a timeout for the connection (except by using socket.setdefaulttimeout() globally, which wasn’t very clean).

    If you don’t mind external dependencies, it looks like httplib2 already has TCP_NODELAY specified.

    You could monkey-patch the library. Because python is a dynamic language and more or less everything is done as a namespace lookup at runtime, you can simply replace the appropriate method on the relevant class:

    :::python
    import httplib
    
    def patch_httplib():
        orig_connect = httplib.HTTPConnection.connect
        def my_connect(self):
            orig_connect(self)
            self.sock.setsockopt(...)
    

    However, this is extremely error-prone as it means that your code becomes quite specific to a particular Python version, as these library functions and classes do change. For example, in 2.7 there’s a _tunnel() method called which uses the socket, so you’d want to hook in the middle of the connect() method – monkey-patching makes that extremely tricky.

    In short, I don’t think there’s an easy answer, I’m afraid.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to disable IPv6. For that the java documentation indicates setting jvm property
I need to disable the multimedia contents in IE Programatically. Is there any way
I need to disable that indexing when I enter on my root directory on
I need to place custom keypad . For that, I need to disable my
I need to disable options with value - Sold Out - in a list
I need to disable Etag header in response so that I can set the
I have a Textbox where I need to disable or enable that on some
The problem I have is that I need to disable struts validation when selecting
Can I lock Dojo slider ? I need disable that user can move slider.
I need to disable the logging when running unit testing automatically so that the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.