OSError: [Errno 24] when multithreading pwntools

446 Views Asked by At

I'm creating a script which will start some threads, and run an input on a binary. The usage is python3 script.py binary input.txt. Here is a reproducible segment that encounters this error:

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()

After 5 or so seconds of run time, I run into this error, aswell as the error: out of pty devices. I am running on ubuntu 20.04.

1

There are 1 best solutions below

1
On BEST ANSWER

It turns out pwntools process API does not close stderr or stdout, so closing them before returning from run, solves the problem.