Launch, Interact, Terminate, and Get All Output When Done This is the use-case this post addresses. But most servers do not, and will just spin forever until killed. If the child process has an orderly termination sequence (such as sending some sort of "quit" command), this is doable. But this would make it tricky to cleanly terminate the child process when we're done with it. Sure, we could launch a child process with n in one thread and interact with it (via a known port, for example) in another thread. This would be difficult to achieve with APIs that just run a child process to completion synchronously, so we'll have to look at some of the lower-level APIs. When we're done, we want to shut down the child process in an orderly way. We launch it as a child process, then connect clients to it and run some testing sequence. Think about testing some server - for example, an HTTP server. In this post, I want to discuss a variation of this task that is less directly addressed: long-running child processes. It comes with several high-level APIs like call, check_output , and (starting with Python 3.5) run that are focused on child processes that our program runs and waits to complete. The Python subprocess module is a powerful Swiss Army knife for launching and interacting with child processes.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |