Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add __repr__ method for AsyncHTTPConnectionPool & other related classes #205

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

owocado
Copy link

@owocado owocado commented Jan 23, 2025

Hello,

I have opened this draft PR as per our discussion in #194
I am not well versed with this codebase but I did attempt to understand and navigate around the codebase to see what I need to cover for this PR and made the necessary changes upto my understanding. I probably missed something. 😄

I have only currently made changes for async public classes.
However, in the linked issue, you said we will need to cover sync counter parts as well, but I'm unsure which ones exactly to cover. So, please guide me on that and I will do the required.

I have run nox -rs format and nox -rs lint commands on my proposed changes before submitting this PR as per the contrinuting guidelines. Please let me know if I missed anything.

Copy link
Author

@owocado owocado left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Self reviewing some questions that I have.

@@ -174,6 +174,9 @@ def __init__(
else resolver
)

def __repr__(self) -> str:
return f"<{self.__class__.__name__} num_pools={self._num_pools}>"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return f"<{self.__class__.__name__} num_pools={self._num_pools}>"
return f"<{self.__class__.__name__} num_pools={len(self.pools)}>"

should this be the more preferred approach? since _num_pools appears to be private attribute.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avoid the call to self.__class__.__name__, we should hardcode it (the name), it will just consume cpu time for no to little impact.

@@ -436,6 +436,9 @@ def __init__(
self._keepalive_idle_window = MINIMAL_KEEPALIVE_IDLE_WINDOW
self._background_monitoring: asyncio.Task | None = None # type: ignore[type-arg]

def __repr__(self) -> str:
return f"<{self.__class__.__name__} host={self.host!r} port={self.port} timeout={self.timeout}>"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return f"<{self.__class__.__name__} host={self.host!r} port={self.port} timeout={self.timeout}>"
return f"<{self.__class__.__name__} host={self.host!r} port={self.port} timeout={self.timeout} retries={self.retries!r} happy_eyeballs={self.happy_eyeballs}>"

should other attributes such as retries and happy_eyeballs be included here? or the way it is as proposed is ok?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

retries seems a bit overwhelming in debug info as it can get pretty complicated.
happy eyeballs on/off is a good info to keep.

@Ousret
Copy link
Member

Ousret commented Jan 28, 2025

There a way to make everything simpler.

Down the hole, we should start by implementing __repr__ in both TrafficPolice and AsyncTrafficPolice

We want key info that we will then be able to sub repr in PoolManager or ConnectionPool easily.

In TrafficPolice we want a quick summary of what we have in a given moment.

Like: <TrafficPolice activecursor=true/false maxsize=A registrysize=B containersize=C idlecount=D saturatedcount=C>.

for idle/saturated, use traffic_state_of function available in the same module. active cursor, you may use .cursor and check if not None.

The repr should hold the lock until the stats is computed (for the sync part).

Then for PoolManager, we basically want: <PoolManager maxsize=A PoliceTrafficREPR>
And ConnectionPool we want: <ConnectionPool maxsize=B PoliceTrafficREPR>.

For both sync and async.

In order:

  • TrafficPolice
  • HttpConnectionPool
  • HttpsConnectionPool
  • PoolManager

  • AsyncTrafficPolice
  • AsyncHttpConnectionPool
  • AsyncHttpsConnectionPool
  • AsyncPoolManager

That should be it.

Regards,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants