python:gevent';s monkey.patch_all会使子进程.check_的速度慢得多
以下是测试脚本:python:gevent';s monkey.patch_all会使子进程.check_的速度慢得多,python,subprocess,gevent,Python,Subprocess,Gevent,以下是测试脚本: from gevent.monkey import patch_all; patch_all() import subprocess from subprocess import STDOUT from tempfile import NamedTemporaryFile import datetime with NamedTempo
from gevent.monkey import patch_all; patch_all()
import subprocess
from subprocess import STDOUT
from tempfile import NamedTemporaryFile
import datetime
with NamedTemporaryFile() as f:
print('Subprocess call at {}'.format(datetime.datetime.now()))
ret = subprocess.check_call(['iptables', '-t', 'mangle', '-L', '-vx'], stdout = f, stderr = STDOUT)
print('Subprocess call end at {}'.format(datetime.datetime.now()))
使用
patch\u all
时,执行时间通常约为600ms,而不使用patch\u all
时,执行时间仅约为30ms。因此,我想知道是什么导致了这种情况,我能做些什么来减少延迟?好吧,这似乎是一个gevent
本身的问题。也许我唯一能做的就是将其回滚到1.1a1
或等待1.3b2
。另一种解决方案是将subprocess=False
传递到patch\u all()