[EMAIL PROTECTED] a écrit : > I wrote: >> And here's a thread example, based on Benjamin's code: > [...] > > Doh! Race condition. Make that: > > import subprocess > import thread > import Queue > > def readtoq(pipe, q): > q.put(pipe.read()) > > cat = subprocess.Popen('cat', shell=True, stdin=subprocess.PIPE, > stdout=subprocess.PIPE) > > myVar = str(range(1000000)) # arbitrary test data. > > q = Queue.Queue() > thread.start_new_thread(readtoq, (cat.stdout, q)) > cat.stdin.write(myVar) > cat.stdin.close() > cat.wait() > myNewVar = q.get() > > assert myNewVar == myVar > print len(myNewVar), "bytes piped around." > > > -- > --Bryan >
Great, it works, thank you Bryan ! Could you explain me why you use a queue instead of a simple array for getting the piped var ? Regards, Ben -- http://mail.python.org/mailman/listinfo/python-list