interface.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/usr/bin/env python
  2. #
  3. # Copyright 2011 Facebook
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  6. # not use this file except in compliance with the License. You may obtain
  7. # a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  13. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  14. # License for the specific language governing permissions and limitations
  15. # under the License.
  16. """Interfaces for platform-specific functionality.
  17. This module exists primarily for documentation purposes and as base classes
  18. for other tornado.platform modules. Most code should import the appropriate
  19. implementation from `tornado.platform.auto`.
  20. """
  21. from __future__ import absolute_import, division, print_function, with_statement
  22. def set_close_exec(fd):
  23. """Sets the close-on-exec bit (``FD_CLOEXEC``)for a file descriptor."""
  24. raise NotImplementedError()
  25. class Waker(object):
  26. """A socket-like object that can wake another thread from ``select()``.
  27. The `~tornado.ioloop.IOLoop` will add the Waker's `fileno()` to
  28. its ``select`` (or ``epoll`` or ``kqueue``) calls. When another
  29. thread wants to wake up the loop, it calls `wake`. Once it has woken
  30. up, it will call `consume` to do any necessary per-wake cleanup. When
  31. the ``IOLoop`` is closed, it closes its waker too.
  32. """
  33. def fileno(self):
  34. """Returns the read file descriptor for this waker.
  35. Must be suitable for use with ``select()`` or equivalent on the
  36. local platform.
  37. """
  38. raise NotImplementedError()
  39. def write_fileno(self):
  40. """Returns the write file descriptor for this waker."""
  41. raise NotImplementedError()
  42. def wake(self):
  43. """Triggers activity on the waker's file descriptor."""
  44. raise NotImplementedError()
  45. def consume(self):
  46. """Called after the listen has woken up to do any necessary cleanup."""
  47. raise NotImplementedError()
  48. def close(self):
  49. """Closes the waker's file descriptor(s)."""
  50. raise NotImplementedError()