本文介绍了获得python和流星对话的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I would like to build a project in meteor (version 0.8) that calls a python script which in turn sends some data back to meteor. I am not sure what the best practice is for doing this at the moment.

DDP看起来不错:
可以用来从Meteor堆栈外部通过DDP协议与Meteor进行通信的客户端."但是python实现似乎未完成: python-ddp -客户端

DDP looks good:
"Clients that can be used to communicate with Meteor through it's DDP protocol, from outside the Meteor stack." But the python implementation looks unfinished: python-ddp-client

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

I guess I could also write directly to mongodb from python but it doesn't sound like the best idea:

  • Can Python write to database and Meteor reactively update
  • How do I access Meteor's mongodb from another client, while meteor is running?

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

Am I missing anything? Is there a better way to do this?

推荐答案

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

If the python script is on the same server you could just call it like in a normal Node.js application:

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和流星对话的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-13 12:51
查看更多