Skip to content

Fix PeriodicCallback usage for Tornado 5#1172

Merged
pitrou merged 7 commits intodask:masterfrom
pitrou:periodic_callback
Oct 31, 2017
Merged

Fix PeriodicCallback usage for Tornado 5#1172
pitrou merged 7 commits intodask:masterfrom
pitrou:periodic_callback

Conversation

@pitrou
Copy link
Copy Markdown
Member

@pitrou pitrou commented Jun 14, 2017

The io_loop argument to PeriodicCallback is removed in Tornado 5.0.

The io_loop argument to PeriodicCallback is removed in Tornado 5.0.
@mrocklin
Copy link
Copy Markdown
Member

Do we have a valid usecase here? Should we try to encourage upstream not to make this change?

@pitrou
Copy link
Copy Markdown
Member Author

pitrou commented Jun 14, 2017

I explained our use case there: https://groups.google.com/d/msg/python-tornado/7JNWKwCTvZs/vI8gdPppAAAJ . I'm not sure @bdarnell is convinced by the argument :-)

@mrocklin
Copy link
Copy Markdown
Member

I'm inclined to wait on the Tornado 5.0 design to be finalized before merging this

@pitrou
Copy link
Copy Markdown
Member Author

pitrou commented Jun 14, 2017

That sounds reasonable.

@bdarnell
Copy link
Copy Markdown

I'd definitely recommend waiting until the Tornado 5.0 design is finalized before merging this, but it's good to have this branch prepared because I'm going to ask you to test a few more things along the way. :)

I'd be happy to meet you halfway on this change: If I move the initialization of self.io_loop from PeriodicCallback.__init__ to PeriodicCallback.start, then you won't need to carry your own version of this class (if I'm understanding everything correctly). You'd still need to remove the io_loop arguments, though, and I'm not sure if it would be possible to do that and retain compatibility with both 4.5 and 5.0 (without more invasive changes to create the PeriodicCallback objects on the thread where they will be used).

@pitrou
Copy link
Copy Markdown
Member Author

pitrou commented Jun 20, 2017

You'd still need to remove the io_loop arguments, though, and I'm not sure if it would be possible to do that and retain compatibility with both 4.5 and 5.0

We could have a thin wrapper which switches based on the Tornado version. Something like:

def PeriodicCallback(callback, callback_time, io_loop=None):
    if tornado.version_info >= (5,):
        return tornado.ioloop.PeriodicCallback(callback, callback_time)
    else:
        return tornado.ioloop.PeriodicCallback(callback, callback_time, io_loop)

@pitrou
Copy link
Copy Markdown
Member Author

pitrou commented Oct 23, 2017

If I move the initialization of self.io_loop from PeriodicCallback.init to PeriodicCallback.start, then you won't need to carry your own version of this class (if I'm understanding everything correctly).

@bdarnell, would you be ready to take a PR doing just this?
(edit: silly typo)

@bdarnell
Copy link
Copy Markdown

If I move the initialization of self.io_loop from PeriodicCallback.init to PeriodicCallback.start, then you won't need to carry your own version of this class (if I'm understanding everything correctly).

@bdarnell, would you be ready to take a PR doing just this?
(edit: silly typo)

Yes.

@mrocklin
Copy link
Copy Markdown
Member

It's nice to see the PeriodicCallback class go away

Comment thread distributed/utils.py
if tornado.version_info >= (5,):
return tornado.ioloop.PeriodicCallback(callback, callback_time)
else:
return tornado.ioloop.PeriodicCallback(callback, callback_time, io_loop)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we ever actually provide an io_loop keyword? If not then can we remove this function entirely?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Well, yes, we do, in a lot of places :-)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It seems odd to me that we are allowed to ignore those imports in Tornado >= 5.0 but need them in <= 5.0.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That's because we fixed PeriodicCallback so that the IO loop is looked up when its start method is called. Before 5.0 the IO loop is set in the constructor, and we call it from another thread.

@pitrou
Copy link
Copy Markdown
Member Author

pitrou commented Oct 31, 2017

@mrocklin are you ok with merging this?

@mrocklin
Copy link
Copy Markdown
Member

Yes. This looks good to me.

I'm looking forward to getting closer to being able to actually try out the new TCPStream stuff on real hardware and this will help.

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.

3 participants