IOLoop wake up trick

205 views
Skip to first unread message

Tudor Golubenco

unread,
Sep 23, 2009, 5:42:18 AM9/23/09
to python-...@googlegroups.com
Hi,

I was reading through the ioloop.py code and found nice the code that wakes
up the poll when it needs to stop the server. It works by sending a
character into pipe
which has one end in the poll list. However, shouldn't this fd be
registered to the READ
event instead of the WRITE event?

Like:

diff --git a/tornado/ioloop.py b/tornado/ioloop.py
index 6c4b727..15ef0b9 100644
--- a/tornado/ioloop.py
+++ b/tornado/ioloop.py
@@ -94,7 +94,7 @@ class IOLoop(object):
self._set_nonblocking(w)
self._waker_reader = os.fdopen(r, "r", 0)
self._waker_writer = os.fdopen(w, "w", 0)
- self.add_handler(r, self._read_waker, self.WRITE)
+ self.add_handler(r, self._read_waker, self.READ)

@classmethod
def instance(cls):

This is a really tiny issue because the poll timeout is set to 0.2
seconds anyway, but
wanted to point it out to make sure I understand it correctly.

Best Regards,
Tudor

--
Tudor Golubenco http://golubenco.org

Beware of bugs in the above code; I have only proved it correct,
not tried it. -- Donald Knuth

mayfield

unread,
Oct 13, 2009, 3:29:29 PM10/13/09
to Tornado Web Server
On NetBSD this change was actually necessary to make the webserver
function.

On Sep 23, 3:42 am, Tudor Golubenco <tudo...@gmail.com> wrote:
> Hi,
>
> I was reading through the ioloop.py code and found nice the code that wakes
> up thepollwhen it needs to stop the server. It works by sending a
> character into pipe
> which has one end in thepolllist. However, shouldn't this fd be
> registered to the READ
> event instead of the WRITE event?
>
> Like:
>
> diff --git a/tornado/ioloop.py b/tornado/ioloop.py
> index 6c4b727..15ef0b9 100644
> --- a/tornado/ioloop.py
> +++ b/tornado/ioloop.py
> @@ -94,7 +94,7 @@ class IOLoop(object):
>          self._set_nonblocking(w)
>          self._waker_reader = os.fdopen(r, "r", 0)
>          self._waker_writer = os.fdopen(w, "w", 0)
> -        self.add_handler(r, self._read_waker, self.WRITE)
> +        self.add_handler(r, self._read_waker, self.READ)
>
>      @classmethod
>      def instance(cls):
>
> This is a really tiny issue because thepolltimeout is set to 0.2
Reply all
Reply to author
Forward
0 new messages