noisyboiler / wampy

Websocket RPC and Pub/Sub for Python applications and microservices
Mozilla Public License 2.0
127 stars 24 forks source link

unale to run the example #71

Closed keiser1080 closed 5 years ago

keiser1080 commented 6 years ago

Hi,

First i have installed lastest version off crossbar into a virtual pypy3 vritualenvironement. Then I have installed wampy using pip inside the virtualenvironement. Thn i have the following crossbar config https://github.com/noisyboiler/wampy/blob/master/wampy/testing/configs/crossbar.json and the following example https://github.com/noisyboiler/wampy/blob/master/docs/examples/services.py runing the router => crossbar start --config crossbar.json And try to launch the service using the run command. It fail

then i have cloned the repo and followed your instruction pip install --editable .[dev] crossbar, and many other lib downgraded to very old version

  Found existing installation: autobahn 18.9.2
    Uninstalling autobahn-18.9.2:
      Successfully uninstalled autobahn-18.9.2
  Found existing installation: crossbar 18.9.2
    Uninstalling crossbar-18.9.2:
      Successfully uninstalled crossbar-18.9.2
  Found existing installation: wampy 0.9.17
    Uninstalling wampy-0.9.17:
      Successfully uninstalled wampy-0.9.17
  Running setup.py develop for wampy
Successfully installed autobahn-0.17.2 colorlog-3.1.4 coverage-4.5.1 crossbar-0.15.0 enum-compat-0.0.2 eventlet-0.20.1 flake8-3.5.0 gevent-websocket-0.10.1 mccabe-0.6.1 mock-1.3.0 pbr-4.3.0 py-1.7.0 pycodestyle-2.3.1 pyflakes-1.6.0 pytest-3.1.3 pytest-capturelog-0.7 shutilwhich-1.1.0 wampy

Running again the router & all the stuff as specified in the doc, And again the same probleme

wampy run docs.examples.services:BinaryNumberService --config ./wampy/testing/configs/crossbar.json
Traceback (most recent call last):
  File "/home/erc/.virtualenvs/pypy3/bin/wampy", line 11, in <module>
    load_entry_point('wampy', 'console_scripts', 'wampy')()
  File "/home/rep/icham/golden/crossbar/wampy/wampy/cli/main.py", line 27, in main
    args.main(args)
  File "/home/rep/icham/golden/crossbar/wampy/wampy/cli/run.py", line 104, in main
    run(app, config_path)
  File "/home/rep/icham/golden/crossbar/wampy/wampy/cli/run.py", line 70, in run
    router = Crossbar(config_path)
  File "/home/rep/icham/golden/crossbar/wampy/wampy/peers/routers.py", line 43, in __init__
    with open(config_path) as data_file:
FileNotFoundError: [Errno 2] No such file or directory: './crossbar/config.json'
ls -al wampy/testing/configs/crossbar.json
-rw-rw-r-- 1 erc erc 1324 Oct 13 19:11 wampy/testing/configs/crossbar.json
noisyboiler commented 6 years ago

thank you @keiser1080. i have some time tomorrow and will look at both your Issues.

keiser1080 commented 6 years ago

thank you @keiser1080. i have some time tomorrow and will look at both your Issues.

If you found the bug i will try tomoro to do a simple flask example. I think i found the issue some more information.

File "/home/erc/.virtualenvs/python3/lib/python3.4/site-packages/wampy/cli/run.py", line 70, in run
    router = Crossbar(config_path)

you try to create an instance of crossbar by giving the config_path as argument but the crossbar class expect as first argument the router url

class Crossbar(ParseUrlMixin):

    def __init__(
        self,
        url="ws://localhost:8080",
        config_path="./crossbar/config.json",
        crossbar_directory=None, 
    ):
keiser1080 commented 6 years ago

update 2 if i swap the arguments order:

        config_path="./crossbar/config.json",
        url="ws://localhost:18080",
        #config_path="./crossbar/config.json",

the router wampy app start with the default config location even if the config is set by the --config argument for wampy run And stop imediatly with the following exception.

 wampy run docs.examples.services:BinaryNumberService --config ./crossbar/config.json  
docs.examples.services ./crossbar/config.json
ws://localhost:18080
ws://localhost:18080
starting up service....
BinaryNumberService is now running and connected.
'gevent._greenlet.Greenlet' object has no attribute 'wait'
Traceback (most recent call last):
  File "/home/erc/.virtualenvs/python3/lib/python3.4/site-packages/wampy/transports/websocket/connection.py", line 70, in receive
    bytes = self.socket.recv(bufsize)
  File "/home/erc/.virtualenvs/python3/lib/python3.4/site-packages/gevent/_socket3.py", line 382, in recv
    self._wait(self._read_event)
  File "src/gevent/_hub_primitives.py", line 265, in gevent.__hub_primitives.wait_on_socket
  File "src/gevent/_hub_primitives.py", line 266, in gevent.__hub_primitives.wait_on_socket
  File "src/gevent/_hub_primitives.py", line 252, in gevent.__hub_primitives._primitive_wait
  File "src/gevent/_hub_primitives.py", line 46, in gevent.__hub_primitives.WaitOperationsGreenlet.wait
  File "src/gevent/_hub_primitives.py", line 46, in gevent.__hub_primitives.WaitOperationsGreenlet.wait
  File "src/gevent/_hub_primitives.py", line 55, in gevent.__hub_primitives.WaitOperationsGreenlet.wait
  File "src/gevent/_waiter.py", line 151, in gevent.__waiter.Waiter.get
  File "src/gevent/_greenlet_primitives.py", line 59, in gevent.__greenlet_primitives.SwitchOutGreenletWithLoop.switch
  File "src/gevent/_greenlet_primitives.py", line 59, in gevent.__greenlet_primitives.SwitchOutGreenletWithLoop.switch
  File "src/gevent/_greenlet_primitives.py", line 63, in gevent.__greenlet_primitives.SwitchOutGreenletWithLoop.switch
  File "src/gevent/__greenlet_primitives.pxd", line 35, in gevent.__greenlet_primitives._greenlet_switch
greenlet.GreenletExit

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "src/gevent/greenlet.py", line 716, in gevent._greenlet.Greenlet.run
  File "/home/erc/.virtualenvs/python3/lib/python3.4/site-packages/wampy/session.py", line 163, in connection_handler
    frame = connection.receive()
  File "/home/erc/.virtualenvs/python3/lib/python3.4/site-packages/wampy/transports/websocket/connection.py", line 71, in receive
    except gevent.greenlet.GreenletExit as exc:
AttributeError: 'module' object has no attribute 'GreenletExit'
2018-10-13T18:50:34Z <Greenlet "Greenlet-0" at 0x7fd3f97ebe48: connection_handler> failed with AttributeError

disconnected

i am using python 3.4.3 (python 2.7 are no more supported by crossbar)

pip freeze
gevent==1.3.7
greenlet==0.4.15
simplejson==3.11.1
six==1.10.0
wampy==0.9.17
keiser1080 commented 6 years ago

update 3

if i install using pip install wampy:

if i intall using pip install -e .[dev]

test_service.py

import datetime
from wampy.peers.clients import Client
from wampy.roles.callee import callee

class DateService(Client):
    """ A service that returns the current date.
    """  
    @callee
    def get_todays_date(self):
        return datetime.date.today().isoformat()

ipython session 1

from test_service import *
client = DateService()
client.start()

ipython session 2

from wampy.peers.clients import Client
with Client() as client:
    result = client.rpc.DateService()

i tryied this

import datetime
from wampy.peers.clients import Client
from wampy.roles.callee import callee
from wampy.roles.subscriber import subscribe

class DateService(Client):
    """ A service that returns the current date.
    """  # NOQA
    @callee
    def get_todays_date(self):
        return datetime.date.today().isoformat()

class SubscribingService(Client):
    """ A service that prints out "foo" topic messages
    """  # NOQA
    @subscribe(topic="foo")
    def foo_handler(self, **kwargs):
        print("foo message received: {}".format(kwargs))

class BinaryNumberService(Client):

    @callee
    def get_binary_number(self, number):
        return bin(number)

class AppRunner(object):

    def __init__(self):
        self.apps = []

    def add_app(self, app):
        self.apps.append(app)

    def run(self):
        for app in self.apps:
            app.start()

    def stop(self):
        for app in self.apps:
            app.stop()

    def wait(self):
        for app in self.apps:
            try:
                app.session._managed_thread.wait()
            except Exception as exc:
                print(exc)
                app.stop()

def run(apps):

    # router = Crossbar(config_path)
    # app = app_class(router=router)
    runner = AppRunner()
    for app in apps:
        app = app()
        runner.add_app(app)
    print("starting up service....")
    runner.run()

    # print("{} is now running and connected.".format(app_name))

    while True:
        try:
            runner.wait()
        except KeyboardInterrupt:

            try:
                runner.stop()
            except KeyboardInterrupt:
                runner.stop()

        else:
            # runner.wait completed
            break

    print('disconnected')

def main():
    apps = [DateService, SubscribingService, BinaryNumberService]
    run(apps)

if __name__ == '__main__':
    main()

but i get 3 times 'gevent._greenlet.Greenlet' object has no attribute 'wait'

noisyboiler commented 6 years ago

Hi @keiser1080 Ok.... time to confess! you are using an untested feature. i've looked at the test cases and there aint no coverage for this. But i see the reason for the failure straight away. The reason is this: wampy used to have eventlet as the async networking backend, but i kept being asked for gevent because this is a more popular project and being used in other peoples apps. gevent does not have the wait API on the green thread object.

Let me think a minute....

keiser1080 commented 6 years ago

:)

It's why I am using wampy. The power of gevent + the power of crossbar. I am waiting for years to be able to talk to crossbar from gevent client using wampy.

Le lun. 15 oct. 2018 à 18:38, simon notifications@github.com a écrit :

Hi @keiser1080 https://github.com/keiser1080 Ok.... time to confess! you are using an untested feature. i've looked at the test cases and there aint no coverage for this. But i see the reason for the failure straight away. The reason is this: wampy used to have eventlet as the async networking backend, but i kept being asked for gevent because this is a more popular project and being used in other peoples apps. gevent does not have the wait API on the green thread object.

Let me think a minute....

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/noisyboiler/wampy/issues/71#issuecomment-429925616, or mute the thread https://github.com/notifications/unsubscribe-auth/ABqDzdptt537Jqwn-J_nQ28d71QKgCv1ks5ulLn9gaJpZM4XavHS .

noisyboiler commented 6 years ago

fear not, this can be solved with a feature that is in master, but not an official release. give me a little more time :)

keiser1080 commented 6 years ago

maybe wait can be replaced by .join() If i good understand we are trying to block a greelet ? here i have sublassed a gevent greenlet:

In [4]: dir(a)
Out[4]: 
['GreenletExit',
 '_Greenlet__cancel_start',
 '_Greenlet__handle_death_before_start',
 '_Greenlet__never_started_or_killed',
 '_Greenlet__start_cancelled_by_kill',
 '_Greenlet__start_completed',
 '_Greenlet__start_pending',
 '_Greenlet__started_but_aborted',
 '__bool__',
 '__class__',
 '__delattr__',
 '__dict__',
 '__doc__',
 '__format__',
 '__getattribute__',
 '__getstate__',
 '__hash__',
 '__init__',
 '__module__',
 '__new__',
 '__nonzero__',
 '__reduce__',
 '__reduce_ex__',
 '__repr__',
 '__setattr__',
 '__sizeof__',
 '__str__',
 '__subclasshook__',
 '_exc_info',
 '_formatinfo',
 '_has_links',
 '_kwargs',
 '_links',
 '_notifier',
 '_notify_links',
 '_raise_exception',
 '_report_error',
 '_report_result',
 '_run',
 '_stack_saved',
 '_start_event',
 'args',
 'dead',
 'error',
 'exc_info',
 'exception',
 'get',
 'getcurrent',
 'gettrace',
 'gr_frame',
 'join',
 'kill',
 'kwargs',
 'link',
 'link_exception',
 'link_value',
 'loop',
 'parent',
 'rawlink',
 'ready',
 'run',
 'settrace',
 'spawn',
 'spawn_later',
 'start',
 'start_later',
 'started',
 'successful',
 'switch',
 'throw',
 'unlink',
 'value']

In [5]: a.join?
Signature: a.join(timeout=None)
Docstring:
Wait until the greenlet finishes or *timeout* expires.
Return ``None`` regardless.
File:      ~/.virtualenvs/base/local/lib/python2.7/site-packages/gevent/greenlet.py
Type:      instancemethod

here some usefull doc: http://sdiehl.github.io/gevent-tutorial/#introduction http://www.gevent.org/api/index.html

noisyboiler commented 6 years ago

@keiser1080 i think that was borked from the beginning! see https://github.com/noisyboiler/wampy/pull/74

noisyboiler commented 5 years ago

fixed by https://github.com/noisyboiler/wampy/pull/74 thank you @keiser1080