我正在尝试生成一个日志文件,其中包含按顺序排列的信息。这就是我所拥有的:
class ExecThread(threading.Thread):
def __init__(self, command):
self.command = command
self._lock = threading.Lock()
threading.Thread.__init__ ( self )
def run ( self ):
self._lock.acquire()
sys.stdout.write(''.join(["Executing: ",self.command,'\n']))
log_file.write(''.join([self.command,'\n']))
os.system(self.command)
self._lock.release()
for ive in locate('*.ive', root_dir):
command = "osgconv"
command = ''.join([command,' ',"-O OutputTextureFiles",' ', infile,' ', outfile,' ',"2>&1"])
conv_osg_thread = ExecThread(command)
conv_osg_thread.start()
conv_osg_thread.join()
我正在执行的命令在结尾处有此重定向:“2>&1"
当我运行这个程序时,我会在消息“Executing blah”之前得到子进程的输出,这个消息列在前面!我以为锁()能修好它,但是不行。