[Twisted-Python] how to change default reactor of twisted.internet?

Hi all,
I have a question about reactor of "twisted.internet" module. I found below;
The default reactor is "select";
[root@karadag internet]# pwd
/usr/lib/python2.6/site-packages/Twisted-10.0.0-py2.6-linux-x86_64.egg/t wisted/internet
[root@karadag internet]# cat reactor.py
# Copyright (c) 2001-2008 Twisted Matrix Laboratories.
# See LICENSE for details.
"""
The reactor is the Twisted event loop within Twisted, the loop which drives
applications using Twisted. The reactor provides APIs for networking,
threading, dispatching events, and more.
The default reactor is based on C{select(2)} and will be installed if this
module is imported without another reactor being explicitly installed.
Regardless of which reactor is installed, importing this module is the correct
way to get a reference to it.
New application code should prefer to pass and accept the reactor as a
parameter where it is needed, rather than relying on being able to import this
module to get a reference. This simplifies unit testing and may make it easier
to one day support multiple reactors (as a performance enhancement), though
this is not currently possible.
@see: L{IReactorCore<twisted.internet.interfaces.IReactorCore>}
@see: L{IReactorTime<twisted.internet.interfaces.IReactorTime>}
@see: L{IReactorProcess<twisted.internet.interfaces.IReactorProcess>}
@see: L{IReactorTCP<twisted.internet.interfaces.IReactorTCP>}
@see: L{IReactorSSL<twisted.internet.interfaces.IReactorSSL>}
@see: L{IReactorUDP<twisted.internet.interfaces.IReactorUDP>}
@see: L{IReactorMulticast<twisted.internet.interfaces.IReactorMulticast>}
@see: L{IReactorUNIX<twisted.internet.interfaces.IReactorUNIX>}
@see: L{IReactorUNIXDatagram<twisted.internet.interfaces.IReactorUNIXDatagram> }
@see: L{IReactorFDSet<twisted.internet.interfaces.IReactorFDSet>}
@see: L{IReactorThreads<twisted.internet.interfaces.IReactorThreads>}
@see: L{IReactorArbitrary<twisted.internet.interfaces.IReactorArbitrary>}
@see: L{IReactorPluggableResolver<twisted.internet.interfaces.IReactorPluggabl eResolver>}
"""
import sys
del sys.modules['twisted.internet.reactor']
from twisted.internet import selectreactor
selectreactor.install()
---------------------------------------------------------------
[root@karadag internet]# twistd --help
Usage: twistd [options]
Options:
...
-r, --reactor= Which reactor to use (see --help-reactors for a list of
possibilities)
--help Display this help and exit.
twistd reads a twisted.application.service.Application out of a file and runs
it.
Commands:
ftp An FTP server.
telnet A simple, telnet-based remote debugging
service.
socks A SOCKSv4 proxy service.
manhole-old An interactive remote debugger service.
portforward A simple port-forwarder.
web A general-purpose web server which can serve
from a filesystem or application resource.
inetd An inetd(8) replacement.
news A news server.
wokkel-component-server An XMPP Component Server
xmpp-router An XMPP Router server
words A modern words server
toc An AIM TOC service.
dns A domain name server.
mail An email service
manhole An interactive remote debugger service
accessible via telnet and ssh and providing
syntax coloring and basic line editing
functionality.
conch A Conch SSH service.
thanks

On 12/12/2012 09:52 AM, Anil KARADAG wrote:
Hi all,
I have a question about reactor of “twisted.internet” module. I found below;
The default reactor is “select”;
In newer versions of Twisted the default is not select, it may be poll or epoll depending on platform.
You are probably asking "how do I set the reactor", this is covered in http://twistedmatrix.com/documents/current/core/howto/choosing-reactor.html - if that is not your question you might want to explain a bit better what you need to know.

What is your question?
On Wed, Dec 12, 2012 at 2:52 PM, Anil KARADAG akaradag@netas.com.tr wrote:
Hi all,****
I have a question about reactor of “twisted.internet” module. I found below;****
The default reactor is “select”;****
[root@karadag internet]# pwd****
/usr/lib/python2.6/site-packages/Twisted-10.0.0-py2.6-linux-x86_64.egg/twisted/internet
*[root@karadag internet]# cat reactor.py*
# Copyright (c) 2001-2008 Twisted Matrix Laboratories.****
# See LICENSE for details.****
"""****
The reactor is the Twisted event loop within Twisted, the loop which drives
applications using Twisted. The reactor provides APIs for networking,****
threading, dispatching events, and more.****
The default reactor is based on C{select(2)} and will be installed if this
module is imported without another reactor being explicitly installed.****
Regardless of which reactor is installed, importing this module is the correct****
way to get a reference to it.****
New application code should prefer to pass and accept the reactor as a****
parameter where it is needed, rather than relying on being able to import this****
module to get a reference. This simplifies unit testing and may make it easier****
to one day support multiple reactors (as a performance enhancement), though
this is not currently possible.****
@see: L{IReactorCore<twisted.internet.interfaces.IReactorCore>}****
@see: L{IReactorTime<twisted.internet.interfaces.IReactorTime>}****
@see: L{IReactorProcess<twisted.internet.interfaces.IReactorProcess>}****
@see: L{IReactorTCP<twisted.internet.interfaces.IReactorTCP>}****
@see: L{IReactorSSL<twisted.internet.interfaces.IReactorSSL>}****
@see: L{IReactorUDP<twisted.internet.interfaces.IReactorUDP>}****
@see: L{IReactorMulticast<twisted.internet.interfaces.IReactorMulticast>}*
@see: L{IReactorUNIX<twisted.internet.interfaces.IReactorUNIX>}****
@see: L{IReactorUNIXDatagram<twisted.internet.interfaces.IReactorUNIXDatagram>}*
@see: L{IReactorFDSet<twisted.internet.interfaces.IReactorFDSet>}****
@see: L{IReactorThreads<twisted.internet.interfaces.IReactorThreads>}****
@see: L{IReactorArbitrary<twisted.internet.interfaces.IReactorArbitrary>}*
@see: L{IReactorPluggableResolver<twisted.internet.interfaces.IReactorPluggableResolver>}
"""****
*import sys*
*del sys.modules['twisted.internet.reactor']*
*from twisted.internet import selectreactor*
*selectreactor.install()*
---------------------------------------------------------------****
[root@karadag internet]# twistd --help****
Usage: twistd [options]****
Options:****
…****
- -r, --reactor= Which reactor to use (see --help-reactors for a
list of*
possibilities)* --help Display this help and exit.****
twistd reads a twisted.application.service.Application out of a file and runs****
it.****
Commands:****
ftp An FTP server.**** telnet A simple, telnet-based remote debugging**
**
service.**** socks A SOCKSv4 proxy service.**** manhole-old An interactive remote debugger service.**
**
portforward A simple port-forwarder.**** web A general-purpose web server which can
serve****
from a filesystem or application resource.
inetd An inetd(8) replacement.**** news A news server.**** wokkel-component-server An XMPP Component Server**** xmpp-router An XMPP Router server**** words A modern words server**** toc An AIM TOC service.**** dns A domain name server.**** mail An email service**** manhole An interactive remote debugger service***
accessible via telnet and ssh and
providing****
syntax coloring and basic line editing***
functionality.****
conch A Conch SSH service.****
thanks****
Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

You should update your twisted install; it'll pick a better default then "select" on most platforms.
For installing other reactors, see individual reactor's documentation, e.g:
https://twistedmatrix.com/documents/current/api/twisted.internet.cfreactor.h...
(because individual reactors may require special magic)
On Wed, Dec 12, 2012 at 3:52 PM, Anil KARADAG akaradag@netas.com.tr wrote:
Hi all,****
I have a question about reactor of “twisted.internet” module. I found below;****
The default reactor is “select”;****
[root@karadag internet]# pwd****
/usr/lib/python2.6/site-packages/Twisted-10.0.0-py2.6-linux-x86_64.egg/twisted/internet
*[root@karadag internet]# cat reactor.py*
# Copyright (c) 2001-2008 Twisted Matrix Laboratories.****
# See LICENSE for details.****
"""****
The reactor is the Twisted event loop within Twisted, the loop which drives
applications using Twisted. The reactor provides APIs for networking,****
threading, dispatching events, and more.****
The default reactor is based on C{select(2)} and will be installed if this
module is imported without another reactor being explicitly installed.****
Regardless of which reactor is installed, importing this module is the correct****
way to get a reference to it.****
New application code should prefer to pass and accept the reactor as a****
parameter where it is needed, rather than relying on being able to import this****
module to get a reference. This simplifies unit testing and may make it easier****
to one day support multiple reactors (as a performance enhancement), though
this is not currently possible.****
@see: L{IReactorCore<twisted.internet.interfaces.IReactorCore>}****
@see: L{IReactorTime<twisted.internet.interfaces.IReactorTime>}****
@see: L{IReactorProcess<twisted.internet.interfaces.IReactorProcess>}****
@see: L{IReactorTCP<twisted.internet.interfaces.IReactorTCP>}****
@see: L{IReactorSSL<twisted.internet.interfaces.IReactorSSL>}****
@see: L{IReactorUDP<twisted.internet.interfaces.IReactorUDP>}****
@see: L{IReactorMulticast<twisted.internet.interfaces.IReactorMulticast>}*
@see: L{IReactorUNIX<twisted.internet.interfaces.IReactorUNIX>}****
@see: L{IReactorUNIXDatagram<twisted.internet.interfaces.IReactorUNIXDatagram>}*
@see: L{IReactorFDSet<twisted.internet.interfaces.IReactorFDSet>}****
@see: L{IReactorThreads<twisted.internet.interfaces.IReactorThreads>}****
@see: L{IReactorArbitrary<twisted.internet.interfaces.IReactorArbitrary>}*
@see: L{IReactorPluggableResolver<twisted.internet.interfaces.IReactorPluggableResolver>}
"""****
*import sys*
*del sys.modules['twisted.internet.reactor']*
*from twisted.internet import selectreactor*
*selectreactor.install()*
---------------------------------------------------------------****
[root@karadag internet]# twistd --help****
Usage: twistd [options]****
Options:****
…****
- -r, --reactor= Which reactor to use (see --help-reactors for a
list of*
possibilities)* --help Display this help and exit.****
twistd reads a twisted.application.service.Application out of a file and runs****
it.****
Commands:****
ftp An FTP server.**** telnet A simple, telnet-based remote debugging**
**
service.**** socks A SOCKSv4 proxy service.**** manhole-old An interactive remote debugger service.**
**
portforward A simple port-forwarder.**** web A general-purpose web server which can
serve****
from a filesystem or application resource.
inetd An inetd(8) replacement.**** news A news server.**** wokkel-component-server An XMPP Component Server**** xmpp-router An XMPP Router server**** words A modern words server**** toc An AIM TOC service.**** dns A domain name server.**** mail An email service**** manhole An interactive remote debugger service***
accessible via telnet and ssh and
providing****
syntax coloring and basic line editing***
functionality.****
conch A Conch SSH service.****
thanks****
Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
participants (4)
-
Anil KARADAG
-
Itamar Turner-Trauring
-
Laurens Van Houtven
-
Stephen Thorne