好的,所以我想使用crossbar.io并在python中构建一个应用程序。
我可以让演示工作但是我的应用程序需要分离使用pycurl来监听长期http连接的线程。
单独,crossbar.io代码和pycurl代码工作,但是当我执行以下操作时,我得到"导入未找到":
import sys
from twisted.internet.defer import inlineCallbacks
from twisted.logger import Logger
from autobahn.twisted.util import sleep
from autobahn.twisted.wamp import ApplicationSession
from autobahn.wamp.exception import ApplicationError
from legacy_misc import Legacy_Listener
client = Legacy_Listener("box01")
client.daemon = True
client.start()
class AppSession(ApplicationSession):
log = Logger()
@inlineCallbacks
def onJoin(self, details):
# SUBSCRIBE to a topic and receive events
#
def onhello(msg):
self.log.info("event for 'onhello' received: {msg}", msg=msg)
yield self.subscribe(onhello, 'com.example.onhello')
self.log.info("subscribed to topic 'onhello'")
# REGISTER a procedure for remote calling
#
def add2(x, y):
self.log.info("add2() called with {x} and {y}", x=x, y=y)
return x + y
yield self.register(add2, 'com.example.add2')
self.log.info("procedure add2() registered")
# PUBLISH and CALL every second .. forever
#
counter = 0
while True:
# PUBLISH an event
#
yield self.publish('com.example.oncounter', counter)
self.log.info("published to 'oncounter' with counter {counter}",
counter=counter)
counter += 1
if counter > 5:
break
# CALL a remote procedure
#
try:
res = yield self.call('com.example.mul2', counter, 3)
self.log.info("mult() called with result: {result}",
result=res)
except ApplicationError as e:
# ignore errors due to the frontend not yet having
# registered the procedure we would like to call
if e.error != 'wamp.error.no_such_procedure':
raise e
yield sleep(1)
legacy_Listener包含带有" import pycurl"的线程代码。 (这个模块本身很好用)
现在,当我将crossbar.io示例代码与我自己的代码混合时,我收到以下错误:
2016-04-09T20:42:09+0100 [Container 26333] Worker process starting (PyPy-EPollReactor) ..
2016-04-09T20:42:13 + 0100 [Controller 26219]具有ID' worker2'和PID 26333开始了
2016-04-09T20:42:13 + 0100 [Container 26333]组件加载失败
Traceback(最近一次调用最后一次):
文件" /opt/crossbar/site-packages/autobahn/wamp/websocket.py",第90行,在onMessage中
self._session.onMessage(MSG)
文件" /opt/crossbar/site-packages/autobahn/wamp/protocol.py",第809行,在onMessage中
on_reply = txaio.as_future(endpoint.fn,* invoke_args,** invoke_kwargs)
文件" /opt/crossbar/site-packages/txaio/tx.py",第339行,as_future
return maybeDeferred(fun,* args,** kwargs)
文件" /opt/crossbar/site-packages/twisted/internet/defer.py" ;,第150行,在mayDeferred中
result = f(* args,** kw)
--- ---
文件" /opt/crossbar/site-packages/crossbar/worker/container.py",第192行,在start_container_component中
create_component = _appsession_loader(config)
文件" / opt / crossbar / site-packages / crossbar / worker / init .py",第74行,在_appsession_loader中
PYTHONPATH = sys.path中
autobahn.wamp.exception.ApplicationError:ApplicationError(error =,args = ['无法导入类\' hello.AppSession \' \ nTraceback(最近一次调用最后一次):\ n文件& #34; /opt/crossbar/site-packages/autobahn/wamp/protocol.py",第809行,在onMessage \ n on_reply = txaio.as_future(endpoint.fn,* invoke_args,** invoke_kwargs)\ n文件" /opt/crossbar/site-packages/txaio/tx.py" ;,第339行,在as_future \ n中返回maybeDeferred(fun,* args,** kwargs)\ n文件" / opt /crossbar/site-packages/twisted/internet/defer.py" ;,第150行,在mayDeferred \ n result = f(* args,** kw)\ n文件" / opt / crossbar / site- package / crossbar / worker / container.py",第192行,在start_container_component \ n create_component = _appsession_loader(config)\ n --- --- \ n文件" / opt / crossbar / site-packages / crossbar / worker / init .py",第58行,在_appsession_loader \ n module = importlib.import_module(module_name)\ n文件" /opt/crossbar/lib-python/2.7 /导入库/
2016-04-09T20:42:13 + 0100 [Container 26333] Python模块搜索路径: 2016-04-09T20:42:13 + 0100 [Container 26333] / home / osboxes / qbtwebmon 2016-04-09T20:42:13 + 0100 [Container 26333] / opt / crossbar / site-packages / crossbar / worker 2016-04-09T20:42:13 + 0100 [Container 26333] / opt / crossbar / bin 2016-04-09T20:42:13 + 0100 [Container 26333] / opt / crossbar / lib_pypy / extensions 2016-04-09T20:42:13 + 0100 [Container 26333] / opt / crossbar / lib_pypy 2016-04-09T20:42:13 + 0100 [Container 26333] /opt/crossbar/lib-python/2.7 2016-04-09T20:42:13 + 0100 [Container 26333] /opt/crossbar/lib-python/2.7/lib-tk 2016-04-09T20:42:13 + 0100 [Container 26333] /opt/crossbar/lib-python/2.7/plat-linux2 2016-04-09T20:42:13 + 0100 [Container 26333] / opt / crossbar / site-packages 2016-04-09T20:42:13 + 0100 [Container 26333] /home/osboxes/qbtwebmon/wamp_venv/lib/python2.7/site-packages 2016-04-09T20:42:13 + 0100 [Container 26333] NativeWorkerSession.onUserError 2016-04-09T20:42:13 + 0100 [Controller 26219] crossbar.error.class_import_failed:无法导入类' hello.AppSession' Traceback(最近一次调用最后一次): 文件" /opt/crossbar/site-packages/autobahn/wamp/protocol.py",第809行,在onMessage中 on_reply = txaio.as_future(endpoint.fn,* invoke_args,** invoke_kwargs) 文件" /opt/crossbar/site-packages/txaio/tx.py",第339行,as_future return maybeDeferred(fun,* args,** kwargs) 文件" /opt/crossbar/site-packages/twisted/internet/defer.py" ;,第150行,在mayDeferred中 result = f(* args,** kw) 文件" /opt/crossbar/site-packages/crossbar/worker/container.py",第192行,在start_container_component中 create_component = _appsession_loader(config) --- --- 文件" / opt / crossbar / site-packages / crossbar / worker / init .py",第58行,在_appsession_loader中 module = importlib.import_module(module_name) 在import_module中的文件" /opt/crossbar/lib-python/2.7/importlib/ init .py",第37行 导入(名称) 文件" /home/osboxes/qbtwebmon/hello.py" ;,第36行,在 来自legacy_misc导入Legacy_Listener exceptions.ImportError:没有名为legacy_misc的模块
2016-04-09T20:42:13 + 0100 [控制器26219]将TERM发送到子过程26272 2016-04-09T20:42:13 + 0100 [Controller 26219]等待26272退出...
现在经过数小时的谷歌搜索后,我意识到pycurl在pypy中不起作用,这就是crossbar.io正在运行的,但我想知道是否有办法说"使用pypy"用于运行crossbar和"使用cpython"用于运行项目?
最后,这不是路径问题,我已经附加了它并为此进行了测试。
答案 0 :(得分:0)
确定,基本上我使用“yum install crossbar”方法安装哪个是用pypy编写的。如果你通过pip安装,它会给你CPython版本,它也比你的pypy版本更快。
注意:pip install crossbar [all]很痛苦,你修复了一个编译问题然后另一个编译问题,只需改为标准的pip安装交叉开关。