everyone! I have a python script, which process input from COM-port.
import sys
for string in sys.stdin:
some_calculation(string)
It runs like this:
cat -v /dev/pts/2 | python3 'process.py'
I want to make it parallel, for example by using GNU parallel. My way is like this: A| parallel B
cat -v /dev/pts/2 | parallel --pipe --recstart '>' python3 process.py
But it is not working.
Any ideas? Many thanks. UPDATE: I found some solution:
cat /dev/pts/2 | parallel -j2 "echo {} | python3 process.py"
Another one by Inian:
cat -v /dev/pts/2 | parallel --recstart '>' --pipe python3 process.py
You can invoke GNU parallel
with the --pipe
option as below:-
--pipe
Spread input to jobs on stdin (standard input). Read a block
of data from stdin (standard input) and give one block of data
as input to one job.
Use the restart
flag before the --pipe
cat -v /dev/pts/2 | parallel --recstart '>' --pipe python3 process.py
More info about GNU parallel
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.