Running multiple Python scripts in parallel using bash

172 Views Asked by At

I want to run a simple python script 100 times in parallel using bash. If I run the python scrips serial everthing is fine, but if I run them in parallel I get the error

stdin is not a tty Presumably because the same python file gets opened multiple times?

Here's the bash file

#!/bin/bash

for i in {1..5}; do
        winpty python test.py &
done

If I remove the & sign everything works fine (serial) but not if I run it in parallel. The Python file is litterally just 1+1

PS: I run python with winpty python and not the usual python because I run it from the git-bash console and that thing has issues... But again, I don't think this is where the issue comes from, because running everything in serial works fine...

1

There are 1 best solutions below

1
Philippe On

I don't have winpty to test following script, but try :

#!/bin/bash

for i in {1..5}; do
        winpty python test.py < /dev/tty > /dev/tty 2>&1 &
done