home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_1801 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  1.5 KB  |  38 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __docformat__ = 'restructuredtext en'
  5. from killableprocess import Popen, PIPE
  6. from threading import Thread
  7. from time import sleep
  8. import os
  9.  
  10. class PipedProcess(Thread):
  11.     
  12.     def __init__(self, command_string, out_callback, end_callback = None):
  13.         self.command_string = command_string
  14.         self.out_callback = out_callback
  15.         self.end_callback = end_callback
  16.         Thread.__init__(self)
  17.  
  18.     
  19.     def run(self):
  20.         env = os.environ
  21.         env['TERM'] = 'xterm'
  22.         process = Popen(self.command_string + ' 2>&1', shell = True, env = env, universal_newlines = True, stdout = PIPE, stdin = PIPE)
  23.         self.process = process
  24.         while True:
  25.             out_char = process.stdout.read(1)
  26.             if out_char == '':
  27.                 if process.poll() is not None:
  28.                     break
  29.                 else:
  30.                     sleep(0.1)
  31.             process.poll() is not None
  32.             self.out_callback(out_char)
  33.         if self.end_callback is not None:
  34.             self.end_callback()
  35.         
  36.  
  37.  
  38.