Advertisement
Guest User

Untitled

a guest
Jan 25th, 2020
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.94 KB | None | 0 0
  1. Главный процесс
  2. import os
  3. import subprocess
  4. import sys
  5.  
  6.  
  7. child = os.path.join(os.path.dirname(__file__), "./child.py")
  8. word  = 'word'
  9. file = ['./parent.py','./child.py']
  10.  
  11. pipes = []
  12. for i in range(0,2):
  13.   command = [sys.executable, child]
  14.   pipe = subprocess.Popen(command, stdin=subprocess.PIPE)
  15.   pipes.append(pipe)
  16.   pipe.stdin.write(word.encode("utf8") + b"\n")
  17.   pipe.stdin.write(file[i].encode("utf8") + b"\n")
  18.   pipe.stdin.close()
  19.  
  20. while pipes:
  21.     pipe = pipes.pop()
  22.     pipe.wait()
  23.  
  24. =====================================================================
  25. Сhild процесс
  26. import sys
  27.  
  28. word = sys.stdin.readline().rstrip()
  29. filename = sys.stdin.readline().rstrip()
  30.  
  31. try:
  32.   with open(filename, "rb") as fh:
  33.     while True:
  34.       current = fh.readline()
  35.       if not current:
  36.           break
  37.       if (word in current ):
  38.           print("find: {0} {1}".format(filename,word))
  39. except :
  40.     pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement