推荐学习书目
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 · 3692 views
    This topic created in 2426 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
        1
    capric  
       Sep 25, 2019
    windows 用 pipe,linux 用 sock
    www5070504
        2
    www5070504  
       Sep 25, 2019
    试试 subprocess?
    Erroad
        3
    Erroad  
       Sep 25, 2019
    使用管道将子进程的 stdin,stdout 重定向
    KomeijiSatori
        4
    KomeijiSatori  
       Sep 25, 2019   ❤️ 1
    lalalakakaka
        5
    lalalakakaka  
       Sep 25, 2019
    LS+1
    websocketd 好评如潮
    Dustyposa
        6
    Dustyposa  
    OP
       Sep 25, 2019
    谢谢大家 我太南了 忘了 asynico.wait 了 这样可以轮询 subprocess 和 wss 的 recieve 了。
    websocketd 我记得是个单独服务吧。 好像操作过
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3113 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 14:34 · PVG 22:34 · LAX 07:34 · JFK 10:34
    ♥ Do have faith in what you're doing.