推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
jugelizi
V2EX  ›  Python

把 Python 代码添加到系统服务中 提供外部调用 如何实现

  •  1
     
  •   jugelizi · Oct 14, 2017 · 3310 views
    This topic created in 3221 days ago, the information mentioned may be changed or developed.

    搜索了下还是不怎么清楚 比如一段计算器代码,传递参数得到计算结果 我安装为系统服务 这样其他语言也可以使用

    8 replies    2017-10-14 15:07:55 +08:00
    YuuuZeee
        1
    YuuuZeee  
       Oct 14, 2017
    你把这个封装成一个 module 里面去,然后放到系统 default 的 python 的 package 里面调用就行了
    azh7138m
        2
    azh7138m  
       Oct 14, 2017 via Android
    简单点就是 RESTful,做成一个 HTTP 服务
    zjqzxc
        3
    zjqzxc  
       Oct 14, 2017
    搜索关键词:进程间通信
    常见的:管道,信号量,消息队列,共享内存,套接字等

    或者如 2#所说,给他做成一个 http 服务
    northisland
        4
    northisland  
       Oct 14, 2017
    ZeroMQ

    http://zeromq.org/

     Ø   Connect your code in any language, on any platform.
     Ø   Carries messages across inproc, IPC, TCP, TIPC, multicast.
     Ø   Smart patterns like pub-sub, push-pull, and router-dealer.
    NoAnyLove
        5
    NoAnyLove  
       Oct 14, 2017
    系统服务?你这是打算用啥系统啊? Windows 下倒是有 COM 接口,不过没有看到过用 Python 写 COM 服务的,不知道行不行。我觉得#3 楼的方案比较靠谱。此外,还可以使用类似 Pyro 这种通过网络调用的服务。
    scriptB0y
        6
    scriptB0y  
       Oct 14, 2017
    听起来远程调用可以做到

    http://python-parallel-programmning-cookbook.readthedocs.io/zh_CN/latest/chapter5/11_A_remote_procedure_call_with_RPyC.html

    大部分语言都支持,不过我不了解能不能跨语言。
    hcnhcn012
        7
    hcnhcn012  
       Oct 14, 2017 via iPhone
    意思是 systemctl start yourservice.service 来启动一个 daemon ?可以参考 shadowsocks 啊,不行就写 socket 老老实实进程间通信好了
    SakuraSa
        8
    SakuraSa  
       Oct 14, 2017
    感觉做成 RPC 服务可以实现。
    可以用现有成熟的 REST/Grpc/Thrift,或者自己写协议(一般没什么必要)
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1106 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 17:36 · PVG 01:36 · LAX 10:36 · JFK 13:36
    ♥ Do have faith in what you're doing.