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

Use thimble #11

Merged
merged 16 commits into from Aug 21, 2014
Merged

Use thimble #11

merged 16 commits into from Aug 21, 2014

Conversation

lvh
Copy link
Contributor

@lvh lvh commented Aug 12, 2014

WIP, with some review points so it doesn't get too off-track.

@lvh
Copy link
Contributor Author

lvh commented Aug 12, 2014

Some points that I hope @manishtomar can answer :)

  • This changes Lock and SetPartitioner to no longer necessarily be externally visible classes. (I may still have to change that, but I don't think they're still necessary). ISTR that the only way you're supposed to use this is client.Lock and client.SetPartitioner, so I don't think it'll matter, but...
  • The docstring for add_listener claimed that this should only be called from the reactor thread. Is that correct, and, if so, why?

@manishtomar
Copy link
Contributor

This changes Lock and SetPartitioner to no longer necessarily be externally visible classes. (I may still have to change that, but I don't think they're still necessary)

I was mainly trying to replicate same design of KazooClient.

ISTR that the only way you're supposed to use this is client.Lock and client.SetPartitioner

Not really. The other way (as per kazoo lib) of using is to create the objects manually with KazooClient instance as argument. These methods are just helpers to that original method.

The docstring for add_listener claimed that this should only be called from the reactor thread. Is that correct, and, if so, why?

Since it has mapping of listeners that can get corrupted when called from multiple threads. In general txkazoo apis are expected to be used in reactor thread only. This is why it has internal mapping of listeners to replay callback in reactor thread.

@lvh
Copy link
Contributor Author

lvh commented Aug 13, 2014

I was mainly trying to replicate same design of KazooClient.

Sure, that makes sense :)

Not really. The other way (as per kazoo lib) of using is to create the objects manually with KazooClient instance as argument. These methods are just helpers to that original method.

Right; but I thought you said at some point that the only way we actually intend to use it is through a client? I could just keep the classes, but since their signature has to change (previously it didn't take a thread pool), it doesn't do much good.

Since it has mapping of listeners that can get corrupted when called from multiple threads. In general txkazoo apis are expected to be used in reactor thread only. This is why it has internal mapping of listeners to replay callback in reactor thread.

Hm; I thought STORE_SUBSCR was guaranteed to be threadsafe in Python?

Thanks for all the comments :)

@lvh
Copy link
Contributor Author

lvh commented Aug 13, 2014

Re: Lock and SetPartitioner being externally visible classes, to clarify: I understand why you did that, I'm asking if it's okay if they no longer are :) (Even if they are, they'd probably get turned into functions with a different signature.)

@manishtomar
Copy link
Contributor

I understand why you did that, I'm asking if it's okay if they no longer are :)

I think its fine if they are not there. Especially since they'll also have the take reactor and thread pool. And thanks a lot for working on this :)

@lvh
Copy link
Contributor Author

lvh commented Aug 18, 2014

It's a bit unfortunate that SetPartitioner does a bunch of blocking IO in __init__, because it means we can never get rid of that class :)

@coveralls
Copy link

Coverage Status

Coverage increased (+3.9%) when pulling d626790 on lvh:use-thimble into 61fabad on rackerlabs:master.

@lvh
Copy link
Contributor Author

lvh commented Aug 19, 2014

I think this is ready for review.

def get_async(self, path, watch=None):
"""See py:func:`kazoo.client.KazooClient.get_async`."""
return self._watch_func(self.client.get_async, path, watch)
def TxKazooClient(reactor, pool, client):
Copy link
Contributor

Choose a reason for hiding this comment

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

This changes the interface. That should be fine right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah. Since the old interface didn't take an explicit pool (and instead just messed with the reactor pool), if we use the reactor pool too, we can't see if the txkazoo issues we're seeing right now are somehow related to using the reactor pool. (I don't think that's a credible cause, but it's one of the few this experiment may tell us about.)

Copy link
Contributor

Choose a reason for hiding this comment

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

Docstrings will be nice :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done: 850ecd1

@manishtomar
Copy link
Contributor

This is great! It will be nice to have some tests for SetPartitioner. Mainly check if __iter__ is delegated to internal object, if its methods come from thimble and if it is created in thread pool with correct args.

@lvh
Copy link
Contributor Author

lvh commented Aug 20, 2014

Thanks for the review @manishtomar ! Pushed the commits addressing the review comments :)

@lvh
Copy link
Contributor Author

lvh commented Aug 20, 2014

Oops, missed that thing about iteration. Fixed that too. I explicitly tested behavior (i.e. that you actually get the underlying __iter__ results) instead of inheritance, so the FakeSetPartitioner grew an extra __iter__ method :)

@coveralls
Copy link

Coverage Status

Coverage increased (+4.69%) when pulling e5041b4 on lvh:use-thimble into 61fabad on rackerlabs:master.

@manishtomar
Copy link
Contributor

LGTM!

@coveralls
Copy link

Coverage Status

Coverage increased (+4.69%) when pulling d0b5f3c on lvh:use-thimble into 61fabad on rackerlabs:master.

lvh added a commit that referenced this pull request Aug 21, 2014
@lvh lvh merged commit 975a802 into rackerlabs:master Aug 21, 2014
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.

None yet

3 participants