推荐学习书目
› 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
Dustyposa
V2EX  ›  Python

如何利用 websocket 给子进程传输 stdin

  •  
  •   Dustyposa · Sep 25, 2019 · 4030 views
    This topic created in 2600 days ago, the information mentioned may be changed or developed.

    请问一下,我现在需要为 oj ( online judge ) 加一个接口,只用来运行 python 代码(解释 python 代码并返回),
    但是,还要增加客户端能传输 input 数据到接口,接口能接受这个 input 并传到正在运行代码的进程。 例如:客户端用户代码:

    data = input()
    print(data)
    

    需要客户端在传输代码后,再传输 input 给服务器。(上面的代码,需要发送两次消息给服务器端)
    所以我决定采用 websocket 来实现。
    但是一边运行子进程,一边接收 input 传回子进程 不知道处理。
    求大佬指点!

    6 replies  •  2019-09-25 21:13:37 +08:00
    capric
    capric
    Sep 25, 2019
    1
    windows 用 pipe,linux 用 sock
    www5070504
    www5070504
    Sep 25, 2019
    2
    试试 subprocess?
    Erroad
    Erroad
    Sep 25, 2019
    3
    使用管道将子进程的 stdin,stdout 重定向
    lalalakakaka
    lalalakakaka
    Sep 25, 2019
    5
    LS+1
    websocketd 好评如潮
    Dustyposa
    Dustyposa
    OP
    Sep 25, 2019
    6
    谢谢大家 我太南了 忘了 asynico.wait 了 这样可以轮询 subprocess 和 wss 的 recieve 了。
    websocketd 我记得是个单独服务吧。 好像操作过
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1480 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 47ms · UTC 06:21 · PVG 14:21 · LAX 22:21 · JFK 01:21
    ♥ Do have faith in what you're doing.