예제 #1
0
 def test_explicit_hub(self):
     oldhub = api.get_hub()
     try:
         api.use_hub(Foo)
         assert isinstance(api.get_hub(), Foo), api.get_hub()
     finally:
         api._threadlocal.hub = oldhub
     check_hub()
예제 #2
0
 def test_explicit_hub(self):
     oldhub = api.get_hub()
     try:
         api.use_hub(Foo)
         assert isinstance(api.get_hub(), Foo), api.get_hub()
     finally:
         api._threadlocal.hub = oldhub
     check_hub()
예제 #3
0
def bench_eventlet(options):
    try:
        import eventlet
    except ImportError:
        if options.ignore_import_errors:
            return
        raise
    print('using eventlet from %s' % eventlet.__file__)
    from eventlet.api import spawn, sleep, use_hub
    if options.eventlet_hub is not None:
        use_hub(options.eventlet_hub)
    test(spawn, sleep, options.kwargs)
예제 #4
0
def bench_eventlet(options):
    try:
        import eventlet
    except ImportError:
        if options.ignore_import_errors:
            return
        raise
    print ('using eventlet from %s' % eventlet.__file__)
    from eventlet.api import spawn, sleep, use_hub
    if options.eventlet_hub is not None:
        use_hub(options.eventlet_hub)
    test(spawn, sleep, options.kwargs)
예제 #5
0
def bench_eventlet1(options):
    try:
        import eventlet
    except ImportError:
        if options.ignore_import_errors:
            return
        raise
    print('using eventlet from %s' % eventlet.__file__)
    from eventlet.proc import spawn_greenlet as spawn
    from eventlet.api import sleep, use_hub
    if options.eventlet_hub:
        use_hub(options.eventlet_hub)
    if options.with_kwargs:
        print('eventlet.proc.spawn_greenlet does support kwargs')
        return
    test(spawn, sleep, options.kwargs)
예제 #6
0
def bench_eventlet1(options):
    try:
        import eventlet
    except ImportError:
        if options.ignore_import_errors:
            return
        raise
    print ('using eventlet from %s' % eventlet.__file__)
    from eventlet.proc import spawn_greenlet as spawn
    from eventlet.api import sleep, use_hub
    if options.eventlet_hub:
        use_hub(options.eventlet_hub)
    if options.with_kwargs:
        print ('eventlet.proc.spawn_greenlet does support kwargs')
        return
    test(spawn, sleep, options.kwargs)
예제 #7
0
def enum_hubs():
    from eventlet.api import use_hub
    hubs = glob('../eventlet/hubs/*.py')
    hubs = [os.path.basename(h)[:-3] for h in hubs]
    hubs = [h for h in hubs if h[:1]!='_']
    hubs = set(hubs)
    hubs.discard('hub')
    hubs -= NOT_HUBS
    result = []
    for hub in hubs:
        try:
            use_hub(hub)
        except Exception, ex:
            print 'Skipping hub %s: %s' % (hub, ex)
        else:
            result.append(hub)
예제 #8
0
def setup_hub(hub, reactor):
    if reactor is not None:
        import_reactor(reactor).install()
    if hub is not None:
        from eventlet.api import use_hub
        try:
            use_hub(hub)
        except ImportError, ex:
            # as a shortcut, try to import the reactor with such name
            try:
                r = import_reactor(hub)
            except ImportError:
                sys.exit('No hub %s: %s' % (hub, ex))
            else:
                r.install()
                use_hub('twistedr')
예제 #9
0
def enum_hubs():
    from eventlet.api import use_hub
    hubs = glob('../eventlet/hubs/*.py')
    hubs = [os.path.basename(h)[:-3] for h in hubs]
    hubs = [h for h in hubs if h[:1] != '_']
    hubs = set(hubs)
    hubs.discard('hub')
    hubs -= NOT_HUBS
    result = []
    for hub in hubs:
        try:
            use_hub(hub)
        except Exception, ex:
            print 'Skipping hub %s: %s' % (hub, ex)
        else:
            result.append(hub)
예제 #10
0
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

"""Integrate eventlet with twisted's reactor mainloop.

You generally don't have to use it unless you need to call reactor.run()
yourself.
"""
from eventlet.hubs.twistedr import BaseTwistedHub
from eventlet.api import use_hub, _threadlocal
from eventlet.support import greenlets as greenlet

use_hub(BaseTwistedHub)
assert not hasattr(_threadlocal, 'hub')
hub = _threadlocal.hub = _threadlocal.Hub(greenlet.getcurrent())