python - 让 python 和 meteor 说话的最佳方式

标签 python meteor

<分区>

我想在 meteor(版本 0.8)中构建一个项目,该项目调用 python 脚本,该脚本又将一些数据发送回 meteor。我不确定目前执行此操作的最佳做​​法是什么。

DDP looks good :
“可用于从 Meteor 堆栈外部通过 DDP 协议(protocol)与 Meteor 通信的客户端。”但是 python 实现看起来还没有完成:python-ddp-client

我想我也可以从 python 直接写入 mongodb 但这听起来不是最好的主意:

我错过了什么吗?有更好的方法吗?

最佳答案

如果 python 脚本在同一台服务器上,您可以像在普通 Node.js 应用程序中一样调用它:

var exec = Npm.require('child_process').exec;
var Fiber = Npm.require('fibers');
var Future = Npm.require('fibers/future');

Meteor.methods({

  callPython: function() {
    var fut = new Future();
    exec('pythonScriptCommand with parameters', function (error, stdout, stderr) {

      // if you want to write to Mongo in this callback
      // you need to get yourself a Fiber
      new Fiber(function() {
        ...
        fut.return('Python was here');
      }).run();

    });
    return fut.wait();
  },

});

关于python - 让 python 和 meteor 说话的最佳方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23011443/

相关文章:

python - 使用 lxml 解析段落标记的子项时缺少子项

python - Django + fcgi = 未显示对 views.py 的新编辑

python - 如何用新句子更新 Doc2Vec 模型?

python - 线程 : AssertionError: group argument must be None for now

javascript - 将 disqus 添加到 meteor.js 项目

javascript - Meteor 中 Iron 路由器的路由问题

javascript - 如何在html中使用 Controller 中的变量

twitter-bootstrap - 在 Meteor 中使工具提示具有反应性

javascript - PDF Js 在 meteor 中不起作用

python - 显示金额 - Python