V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 · 2019-09-25 16:35:03 +08:00 · 2846 次点击
    这是一个创建于 1668 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

    data = input()
    print(data)
    

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

    6 条回复    2019-09-25 21:13:37 +08:00
    capric
        1
    capric  
       2019-09-25 17:17:27 +08:00
    windows 用 pipe,linux 用 sock
    www5070504
        2
    www5070504  
       2019-09-25 17:18:39 +08:00
    试试 subprocess?
    Erroad
        3
    Erroad  
       2019-09-25 17:21:50 +08:00
    使用管道将子进程的 stdin,stdout 重定向
    KomeijiSatori
        4
    KomeijiSatori  
       2019-09-25 17:23:54 +08:00   ❤️ 1
    lalalakakaka
        5
    lalalakakaka  
       2019-09-25 17:31:57 +08:00
    LS+1
    websocketd 好评如潮
    Dustyposa
        6
    Dustyposa  
    OP
       2019-09-25 21:13:37 +08:00
    谢谢大家 我太南了 忘了 asynico.wait 了 这样可以轮询 subprocess 和 wss 的 recieve 了。
    websocketd 我记得是个单独服务吧。 好像操作过
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1059 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 23:09 · PVG 07:09 · LAX 16:09 · JFK 19:09
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.