Advertisement
jwinterm

multiprocessANDpexpectEXAMPLEnokivy

May 31st, 2014
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.71 KB | None | 0 0
  1. import sys
  2. if sys.platform == 'win32':
  3.     import winpexpect
  4. elif sys.platform == 'linux' or sys.platform == 'linux32':
  5.     import pexpect
  6. from multiprocessing import Process, Queue
  7.  
  8. def puthello(q):
  9.     if sys.platform == 'win32':
  10.         child = winpexpect.winspawn('cmd', timeout=9000)
  11.     elif sys.platform == 'linux' or sys.platform == 'linux32':
  12.         child = pexpect.spawn('bash', timeout=9000)
  13.     while True:
  14.         child.sendline('echo hello')
  15.         child.expect('\r\n')
  16.         q.put(child.before+child.after)
  17.  
  18.  
  19. q = Queue()
  20. p = Process(target=puthello, args=(q,))
  21. def launchprocess():
  22.     p.start()
  23.     while True:
  24.         print q.get()
  25.  
  26.  
  27. if __name__ == '__main__':
  28.     launchprocess()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement