GithubHelp home page GithubHelp logo

unale to run the example about wampy HOT 10 CLOSED

noisyboiler avatar noisyboiler commented on September 4, 2024
unale to run the example

from wampy.

Comments (10)

noisyboiler avatar noisyboiler commented on September 4, 2024 1

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

from wampy.

noisyboiler avatar noisyboiler commented on September 4, 2024 1

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

from wampy.

noisyboiler avatar noisyboiler commented on September 4, 2024 1

fixed by #74
thank you @keiser1080

from wampy.

keiser1080 avatar keiser1080 commented on September 4, 2024

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, 
    ):

from wampy.

keiser1080 avatar keiser1080 commented on September 4, 2024

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

from wampy.

keiser1080 avatar keiser1080 commented on September 4, 2024

update 3

if i install using pip install wampy:

  • i am able to expose a procedure using client.start from ipython
  • i am not able to call the procedure

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

  • i am able to expose a procedure using client.start from ipython
  • i am able to call the remote procedure using another ipython session,
    using old and new vesion of crossbar

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'

from wampy.

noisyboiler avatar noisyboiler commented on September 4, 2024

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....

from wampy.

keiser1080 avatar keiser1080 commented on September 4, 2024

from wampy.

keiser1080 avatar keiser1080 commented on September 4, 2024

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

from wampy.

noisyboiler avatar noisyboiler commented on September 4, 2024

@keiser1080
i think that was borked from the beginning!
see #74

from wampy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.