结合使用node.js和Python [英] Combining node.js and Python

查看:140
本文介绍了结合使用node.js和Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Node.js非常适合我们的Web项目,但是很少有我们希望使用Python的计算任务.我们已经为他们准备了Python代码. 我们非常关注速度,如何以异步非阻塞方式从node.js调用Python工人"的最优雅方法是什么?

Node.js is a perfect match for our web project, but there are few computational tasks for which we would prefer Python. We also already have a Python code for them. We are highly concerned about speed, what is the most elegant way how to call a Python "worker" from node.js in an asynchronous non-blocking way?

推荐答案

对于node.js和Python服务器之间的通信,如果两个进程都在同一服务器上运行,则我将使用Unix套接字,否则将使用TCP/IP套接字.对于封送协议,我将使用JSON或协议缓冲区.如果线程Python成为瓶颈,请考虑使用 Twisted Python , 提供与node.js相同的事件驱动的并发性.

For communication between node.js and Python server, I would use Unix sockets if both processes run on the same server and TCP/IP sockets otherwise. For marshaling protocol I would take JSON or protocol buffer. If threaded Python shows up to be a bottleneck, consider using Twisted Python, which provides the same event driven concurrency as do node.js.

如果您喜欢冒险,请学习 clojure ( clojure-py ),而您将获得与Java,JavaScript(包括node.js),CLR和Python上的现有代码一起运行并与之互操作的相同语言.只需使用clojure数据结构,您就能获得出色的编组协议.

If you feel adventurous, learn clojure (clojurescript, clojure-py) and you'll get the same language that runs and interoperates with existing code on Java, JavaScript (node.js included), CLR and Python. And you get superb marshalling protocol by simply using clojure data structures.

这篇关于结合使用node.js和Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆