interface.py 2.2 KB

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