|
Revision 20, 1.1 KB
(checked in by amirh, 2 years ago)
|
|
|
| Line | |
|---|
| 1 | import os |
|---|
| 2 | import subprocess |
|---|
| 3 | import sys |
|---|
| 4 | from threading import Thread |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | class Timeout(Thread): |
|---|
| 8 | run = True |
|---|
| 9 | runs = 1 |
|---|
| 10 | run_forever = 0 |
|---|
| 11 | timeout = 0 |
|---|
| 12 | def kill(self): |
|---|
| 13 | self.run = False |
|---|
| 14 | def set_runs(self, runs): |
|---|
| 15 | self.runs = runs |
|---|
| 16 | def set_run_forever(self): |
|---|
| 17 | self.run_forever = 1 |
|---|
| 18 | def set_timeout(self,x): |
|---|
| 19 | self.timeout = x |
|---|
| 20 | def run(self): |
|---|
| 21 | while self.runs > 0 and self.run: |
|---|
| 22 | Thread.run(self) |
|---|
| 23 | if(self.timeout): |
|---|
| 24 | time.sleep(self.timeout) |
|---|
| 25 | self.runs = self.runs + self.run_forever - 1 |
|---|
| 26 | |
|---|
| 27 | xst = subprocess.Popen('xst', stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | def LogPrint(Port,File): |
|---|
| 31 | ln = Port.readline() |
|---|
| 32 | print ln |
|---|
| 33 | File.write(ln) |
|---|
| 34 | |
|---|
| 35 | logfile = open('logfile','w') |
|---|
| 36 | |
|---|
| 37 | xst_io = Timeout(target=LogPrint, args=[xst.stdout,logfile]) |
|---|
| 38 | xst_io.set_run_forever() |
|---|
| 39 | xst_io.start() |
|---|
| 40 | xst.stdin.write('help -arch virtex5 -command run\n') |
|---|
| 41 | |
|---|
| 42 | ## |
|---|
| 43 | ##xst_io.kill() |
|---|
| 44 | ## |
|---|
| 45 | ##xst.stdin.write('quit\n') |
|---|
| 46 | ## |
|---|
| 47 | ##logfile.close() |
|---|