OSError:[Erno 24]当多线程处理pwntools时



我正在创建一个脚本,该脚本将启动一些线程,并在二进制文件上运行输入。用法为python3 script.py binary input.txt。以下是一个遇到此错误的可复制段:

from pwn import *
import threading
inputFile = ""
try:
inputFile = open(sys.argv[2], 'r')
inputStr = inputFile.read().strip()
inputFile.close()
except OSError:
sys.exit()
def run(testStr) :
p = process("./"+sys.argv[1])
p.sendline(testStr)
p.shutdown()
return p.poll(block = True)
def opens() :
while True:
run(inputStr)

for i in range(0,10):
thread = threading.Thread(target = opens)
thread.start()

运行大约5秒后,我遇到了这个错误,还有错误:out of pty devices。我正在运行ubuntu 20.04。

事实证明pwntools进程API不会关闭stderr或stdout,因此在从运行返回之前关闭它们可以解决问题。

最新更新