I figured it out! There was no problem with my code. The problem was with stockfish. I found out on the perftree github page that its last commit was 3 years ago. So I downloaded stockfish 13, which came out before the last commit, and it works!