Autobahn throw an error when lunched a second time

#1
Hi,
I am new with Autobahn Python/JS and after serval days of reading the sources/exemples/documentation and different articles in different languages (English, French and German) i still don't know how to correctly use Autobahn.

What i want is to use RPC in Python to Python, and i started from an exemple, now i have this :
from asyncio import coroutine, get_event_loop

from autobahn.asyncio.wamp import ApplicationSession, ApplicationRunner

def test(number1, number2):
    class Component(ApplicationSession):
        """
        An application component that publishes an event every second.
        """
        result = None

        @coroutine
        def onJoin(self, details):
            try:
                Component.result = yield from self.call(u'com.myapp.topic2222222222', number1, number2)
                print('Got: {}'.format(Component.result))

            except Exception as e:
                Component.result = e
            self.leave()

        def onLeave(self, details):
            self.disconnect()

        def onDisconnect(self):
            get_event_loop().stop()

    runner = ApplicationRunner("wss://demo.crossbar.io/ws", "realm1")
    runner.run(Component)

    return Component.result

This script works but actually due to something i don't understand i can run test() only one time, when i run it two times in parallel, i have this error :

Traceback (most recent call last):
File “/vagrant/venv/remote/lib/python3.4/site-packages/celery/app/trace.py”, line 240, in trace_task
R = retval = fun(*args, **kwargs)
File “/vagrant/venv/remote/lib/python3.4/site-packages/celery/app/trace.py”, line 438, in protected_call
return self.run(*args, **kwargs)
File “/vagrant/fennek/tasks/tasks.py”, line 34, in test
runner.run(Component)
File “/vagrant/venv/remote/lib/python3.4/site-packages/autobahn/asyncio/wamp.py”, line 185, in run
loop.run_until_complete(coro)
File “/usr/lib/python3.4/asyncio/base_events.py”, line 203, in run_until_complete
self.run_forever()
File “/usr/lib/python3.4/asyncio/base_events.py”, line 184, in run_forever
self._run_once()
File “/usr/lib/python3.4/asyncio/base_events.py”, line 787, in _run_once
event_list = self._selector.select(timeout)
AttributeError: ‘NoneType’ object has no attribute ‘select’

Also, it's take a lot of time (6 seconds) to do this, it's probably because i disconnect and ask a new session each time i run test() but i don't know how to reuse the same session so it's take less time.

I found this https://github.com/tavendo/AutobahnPython/blob/master/examples/twisted/wamp/session/fromoutside/client.py but it seems to be too old and not up to date + it's for WebSockets not for WAMP RPC
I find the documentation pretty clear and useful but as a newbie i can do nothing without a good, up to date, well commented exemples :-(
PS : Sorry for my bad english
0 Likes

#2

Hi,

it’s probably easier to help if you explain what you want to do. For example, have 2 Python application components written using asyncio (and/or Python 3). If so, have 2 guest workers configured in Crossbar.io, each invoking Python 3 with your AutobahnPython/asyncio based code. One file per component.

Hope that helps,
/Tobias

···

Am Freitag, 6. Februar 2015 20:36:07 UTC+1 schrieb Payten:

Hi,
I am new with Autobahn Python/JS and after serval days of reading the sources/exemples/documentation and different articles in different languages (English, French and German) i still don't know how to correctly use Autobahn.


What i want is to use RPC in Python to Python, and i started from an exemple, now i have this :
from asyncio import coroutine, get_event_loop

from autobahn.asyncio.wamp import ApplicationSession, ApplicationRunner

def test(number1, number2):
    class Component(ApplicationSession):
        """
        An application component that publishes an event every second.
        """
        result = None

        @coroutine
        def onJoin(self, details):
            try:
                Component.result = yield from self.call(u'com.myapp.topic2222222222', number1, number2)
                print('Got: {}'.format(Component.result))

            except Exception as e:
                Component.result = e
            self.leave()

        def onLeave(self, details):
            self.disconnect()

        def onDisconnect(self):
            get_event_loop().stop()

    runner = ApplicationRunner("wss://[demo.crossbar.io/ws](http://demo.crossbar.io/ws)", "realm1")
    runner.run(Component)

    return Component.result

This script works but actually due to something i don’t understand i can run test() only one time, when i run it two times in parallel, i have this error :



Traceback (most recent call last):
  File "/vagrant/venv/remote/lib/python3.4/site-packages/celery/app/trace.py", line 240, in trace_task
    R = retval = fun(*args, **kwargs)
  File "/vagrant/venv/remote/lib/python3.4/site-packages/celery/app/trace.py", line 438, in __protected_call__
    return self.run(*args, **kwargs)
  File "/vagrant/fennek/tasks/tasks.py", line 34, in test
    runner.run(Component)
  File "/vagrant/venv/remote/lib/python3.4/site-packages/autobahn/asyncio/wamp.py", line 185, in run
    loop.run_until_complete(coro)
  File "/usr/lib/python3.4/asyncio/base_events.py", line 203, in run_until_complete
    self.run_forever()
  File "/usr/lib/python3.4/asyncio/base_events.py", line 184, in run_forever
    self._run_once()
  File "/usr/lib/python3.4/asyncio/base_events.py", line 787, in _run_once
    event_list = self._selector.select(timeout)
AttributeError: 'NoneType' object has no attribute 'select'
Also, it's take a lot of time (6 seconds) to do this, it's probably because i disconnect and ask a new session each time i run test() but i don't know how to reuse the same session so it's take less time.
I found this [https://github.com/tavendo/AutobahnPython/blob/master/examples/twisted/wamp/session/fromoutside/client.py](https://github.com/tavendo/AutobahnPython/blob/master/examples/twisted/wamp/session/fromoutside/client.py) but it seems to be too old and not up to date + it's for WebSockets not for WAMP RPC
I find the documentation pretty clear and useful but as a newbie i can do nothing without a good, up to date, well commented exemples :-(
PS : Sorry for my bad english
0 Likes