好的,所以我想使用 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 [控制器 26219] ID 为“worker2”和 PID 26333 的容器已启动 2016-04-09T20:42:13+0100 [容器 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 返回MaybeDeferred(fun, *args, **kwargs) 文件“/opt/crossbar/site-packages/twisted/internet/defer.py”,第 150 行,在 MaybeDeferred 结果 = 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/在里面.py",第 74 行,在 _appsession_loader pythonpath=sys.path autobahn.wamp.exception.ApplicationError: ApplicationError(error=, args=['Failed to import class \'hello.AppSession\'\nTraceback (最近一次调用最后) :\n 文件“/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 return maybeDeferred(fun, *args, **kwargs)\n 文件 "/opt/crossbar/site-packages/twisted /internet/defer.py”,第 150 行,在可能延迟中\n 结果 = f(*args, **kw)\n 文件“/opt/crossbar/site-packages/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 模块 = importlib.import_module(module_name)\n 文件 "/opt/crossbar/lib-python/2.7/importlib/init .py ",第 37 行,在 import_module\n 导入(名称)\n 文件“/home/osboxes/qbtwebmon/hello.py”,第 36 行,\n from legacy_misc import Legacy_Listener\nexceptions.ImportError: No module named legacy_misc\n'], kwargs={'pythonpath': [u'/home/osboxes/qbtwebmon', '/opt/crossbar/site-packages/crossbar/worker', '/opt/crossbar/bin', '/opt/crossbar/lib_pypy/ extensions', '/opt/crossbar/lib_pypy', '/opt/crossbar/lib-python/2.7', '/opt/crossbar/lib-python/2.7/lib-tk', '/opt/crossbar/lib-python /2.7/plat-linux2', '/opt/crossbar/site-packages', '/home/osboxes/qbtwebmon/wamp_venv/lib/python2.7/site-packages']}, enc_algo=None)
2016-04-09T20:42:13+0100 [容器 26333] Python 模块搜索路径:2016-04-09T20:42:13+0100 [容器 26333] /home/osboxes/qbtwebmon 2016-04-09T20:42:13 +0100 [容器 26333] /opt/crossbar/site-packages/crossbar/worker 2016-04-09T20:42:13+0100 [容器 26333] /opt/crossbar/bin 2016-04-09T20:42:13+0100 [容器 26333] /opt/crossbar/lib_pypy/扩展 2016-04-09T20:42:13+0100 [容器 26333] /opt/crossbar/lib_pypy 2016-04-09T20:42:13+0100 [容器 26333] /opt/crossbar/lib-python/2.7 2016-04- 09T20:42:13+0100 [容器 26333] /opt/crossbar/lib-python/2.7/lib-tk 2016-04-09T20:42:13+0100 [容器 26333] /opt/crossbar/lib-python/2.7 /plat-linux2 2016-04-09T20:42:13+0100 [容器 26333] /opt/crossbar/site-packages 2016-04-09T20:42:13+0100 [容器 26333] /home/osboxes/qbtwebmon/wamp_venv /lib/python2.7/site-packages 2016-04-09T20:42:13+0100 [容器 26333] NativeWorkerSession.onUserError 2016-04-09T20:42:13+0100 [控制器 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 中返回可能延迟(有趣,*args, **kwargs) 文件“/opt/crossbar/site-packages/twisted/internet/defer.py”,第 150 行,在可能延迟结果 = 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/第 150 行,在可能延迟结果中 = 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/第 150 行,在可能延迟结果中 = 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 模块 = importlib.import_module(module_name) 文件中“/opt/crossbar/lib-python/2.7/importlib/init .py ”,第 37 行,在 import_module 导入(名称)文件中“/ home/osboxes/qbtwebmon/hello.py”,第 36 行,从 legacy_misc 导入 Legacy_Listener exceptions.ImportError: No module named legacy_misc
2016-04-09T20:42:13+0100 [控制器 26219] 将 TERM 发送到子进程 26272 2016-04-09T20:42:13+0100 [控制器 26219] 等待 26272 退出...
现在经过数小时的谷歌搜索,我意识到 pycurl 在 pypy 中不起作用,这是 crossbar.io 正在运行的,但我想知道是否有办法说“使用 pypy”来运行交叉开关和“使用 cpython”运行项目?
最后,这不是路径问题,我已附加并对此进行了测试。