简体   繁体   English

如何与后台Python实例进行通信?

[英]How can I communicate with a backgrounded Python instance?

Environment preamble: 环境序言:

I write Python code in Vim for Maya on Linux. 我在Linux上用Vim for Maya编写Python代码。 I'm using nose for test discovery and execution, and I'm using its attribute plugin to decorate Maya-only test classes. 我正在使用nose进行测试发现和执行,我正在使用它的属性插件来装饰仅限Maya的测试类。 I have mappings in Vim to run the non-Maya tests in regular Python, and the Maya tests through Maya's mayapy executable, which gives me access to the scene, and the maya.cmds module. 我在Vim中有映射来在常规Python中运行非Maya测试,而Maya通过Maya的mayapy可执行文件进行测试,这使我能够访问场景和maya.cmds模块。

Actual problem: 实际问题:

mayapy takes 6 seconds to start up every time I hit my in-Maya tests Vim mapping. 每当我点击我的in-Maya测试Vim映射时, mayapy需要6秒才能启动。 It gets really tedious. 这真的很乏味。 The non-Maya tests happen as fast as I can hit their mapping. 非Maya测试的发生速度和我的映射速度一样快。 It's helped me abstract more away from Maya, to avoid that tiny, all-day pain, but I'd still like it gone. 它帮助我从Maya中抽出更多的东西,以避免那种微小的,全天的痛苦,但我仍然喜欢它消失了。 6 seconds starts to feel like a long time. 6秒开始感觉很长一段时间。 There are tricks for working asynchronously in Vim, but I don't like to move ahead without seeing if my tests passed. 在Vim中有异步工作的技巧,但我不想在没有看到我的测试通过的情况下继续前进。 I've asked Autodesk (makers of Maya), and they say there's no way around the startup time. 我问过Autodesk(Maya的制造商),他们说创业时间没有办法。

Question: 题:

What I think I want is to fire up mayapy in the background, and then when I hit my Vim mapping, have it connect to the waiting Python instance and call the nose.run() command. 我想要的是在后台启动mayapy ,然后当我点击我的Vim映射时,让它连接到等待的Python实例并调用nose.run()命令。 I feel like mkfifo is the way to go, but I'm unsure of the particulars. 我觉得mkfifo是要走的路,但我不确定细节。 How can I do this (through mkfifo or otherwise)? 我怎么能这样做(通过mkfifo或其他方式)?

I am assuming mayapy is like a repl and you can hit commands on to it like the mentioned nose.run() . 我假设mayapy就像一个repl,你可以像上面提到的nose.run()一样点击命令。 If that is the case, I would recommend using the vim plugin tslime which allows you to be able to send stuff from a vim buffer to another tmux pane / window. 如果是这种情况,我建议使用vim插件tslime ,它允许您将内容从vim缓冲区发送到另一个tmux窗格/窗口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM