Python: when to use pty.fork() versus os.fork()

前端 未结 3 1158
别跟我提以往
别跟我提以往 2021-02-05 14:52

I\'m uncertain whether to use pty.fork() or os.fork() when spawning external background processes from my app. (Such as chess engines)

I want t

3条回答
  •  暖寄归人
    2021-02-05 15:06

    In the past I've always used the subprocess module for this. It provides a good api for communicating with subprocesses.

    You can use call(*popenargs, **kwargs) for blocking execution of them, and I believe using the Popen class can handle async execution.

    Check out the docs for more info.

    As far as using os.fork vs pty.fork, both are highly platform dependent, and neither will work (or at least is tested) with windows. The pty module seems to be the more constrained of the two by reading the docs. The main difference being the pseudo terminal aspect. So if you aren't willing to architect your code in such a way as to be able to use the subprocess module, I'd probably go with os.fork instead of pty.fork.

提交回复
热议问题