使用Python,我试图确定是应该使用multiprocessing
,threading
还是asyncio
,第一步是确定程序是否受CPU限制或IO绑定。
我的代码中最慢的部分是与异步编程之前创建的子进程进行交互。相关代码如下:
# First curl command to existing JS console running on my machine
curl_command = <curl command here>
cmd = shlex.split(curl_command)
subprocess.Popen(cmd, stderr=subprocess.DEVNULL)
# Different curl command
self.other_command = self._other_curl_command()
# Interact with an existing JS console running on my machine
output_one = call_one()
output_two = call_two()
output_three = call_three()
请务必注意,这些调用是针对我在计算机上运行的JS控制台的。这些是受I / O约束的活动吗?如果是这样,我应该使用threading
/ asyncio
吗?