开发者

spawn safe, platform-independent dummy process in Python

开发者 https://www.devze.com 2023-03-08 19:43 出处:网络
I\'m writing some code that needs to run on different OS platforms and interact with separate processes. To write tests for it, I need to be able to create processes from python that do nothing but wa

I'm writing some code that needs to run on different OS platforms and interact with separate processes. To write tests for it, I need to be able to create processes from python that do nothing but wait to be signaled to stop. I would like to be able to create some processes that recursively create more.

Also (this part might be a little strange), it would be best for my testing if I were able to create processes that weren't children of the creating process, so I c开发者_开发知识库ould emulate conditions where, e.g., os.waitpid won't have permission to interact with the process, or where one process signals a factory to create a process rather than creating it directly.


If you're using Python 2.6 the multiprocessing package has some stuff you might find useful.

There's a very simple example on my github. If you run spawner it will create 3 processes that run seperately, but use a channel to talk back to the spawner. So if you kill the spawner process the others you have started will die. I'm afraid there's a lot of redundant code in here, I'm in the middle of a refactoring, but I hope it gives a basic idea.

0

精彩评论

暂无评论...
验证码 换一张
取 消