Initial import to Tizen
[profile/ivi/python-twisted.git] / twisted / internet / default.py
1 # -*- test-case-name: twisted.internet.test.test_default -*-
2 # Copyright (c) Twisted Matrix Laboratories.
3 # See LICENSE for details.
4
5 """
6 The most suitable default reactor for the current platform.
7
8 Depending on a specific application's needs, some other reactor may in
9 fact be better.
10 """
11
12 __all__ = ["install"]
13
14 from twisted.python.runtime import platform
15
16
17 def _getInstallFunction(platform):
18     """
19     Return a function to install the reactor most suited for the given platform.
20
21     @param platform: The platform for which to select a reactor.
22     @type platform: L{twisted.python.runtime.Platform}
23
24     @return: A zero-argument callable which will install the selected
25         reactor.
26     """
27     # Linux: epoll(7) is the fault, since it scales well.
28     #
29     # OS X: poll(2) is not exposed by Python because it doesn't
30     # support all file descriptors (in particular, lack of PTY support
31     # is a problem) -- see <http://bugs.python.org/issue5154>. kqueue
32     # reactor is being rewritten (see
33     # <http://twistedmatrix.com/trac/ticket/1918>), and also has same
34     # restriction as poll(2) as far PTY support goes.
35     #
36     # Windows: IOCP should eventually be default, but still has some serious
37     # bugs, e.g. <http://twistedmatrix.com/trac/ticket/4667>.
38     #
39     # We therefore choose epoll(7) on Linux, poll(2) on other non-OS X POSIX
40     # platforms, and select(2) everywhere else.
41     try:
42         if platform.isLinux():
43             try:
44                 from twisted.internet.epollreactor import install
45             except ImportError:
46                 from twisted.internet.pollreactor import install
47         elif platform.getType() == 'posix' and not platform.isMacOSX():
48             from twisted.internet.pollreactor import install
49         else:
50             from twisted.internet.selectreactor import install
51     except ImportError:
52         from twisted.internet.selectreactor import install
53     return install
54
55
56 install = _getInstallFunction(platform)