Ejemplo n.º 1
0
    def serveUploadResult(self, qs):
        global maybeIsInSubprocess
        global isPostEntered

        self.send_response(200)
        self.sendDefaultHeaders()
        self.end_headers()

        inFileName = os.path.join("build", "child_output.txt")
        inFile = None

        maybeIsInSubprocess = True
        startWait = time.time()
        while not isPostEntered:
            now = time.time()
            # wait a maximum of 10 seconds
            if now - startWait > 10.0:
                break
        isPostEntered = False

        result = ""
        try:
            # wait until subprocess output file appears
            while maybeIsInSubprocess or inFile == None:
                try:
                    inFile = open(inFileName, "rb")
                except:
                    inFile = None
                    time.sleep(0.001)

            if inFile:
                uploadLine = ""
                while True:
                    if utils.fileIsOver(inFile):
                        if maybeIsInSubprocess:
                            time.sleep(0.001)
                            continue
                        else:
                            break
                    # read one symbol
                    c = inFile.read(1)
                    uploadLine += c
                    if c == '\n':
                        # if newline reached, print out the current line
                        result += uploadLine
                        uploadLine = ""
        except:
            raise
        finally:
            # clean up
            try:
                if inFile: inFile.close()
                os.remove(inFileName)
            except:
                pass
        self.writeChunk(result)
Ejemplo n.º 2
0
    def serveUploadResult(self, qs):
        global maybeIsInSubprocess
        global forceInterrupt

        self.send_response(200)
        self.sendDefaultHeaders()
        self.end_headers()

        inFileName = os.path.join("build", "child_output.txt")
        inFile = None

        try:
            limit = int(qs['line'][0])
        except:
            limit = 100000

        if limit == 1:
            # first time in this function
            maybeIsInSubprocess = True

        uploadLine = ""
        try:
            # wait until subprocess output file appears
            while inFile == None:
                try:
                    if forceInterrupt:
                        self.writeChunk("Finished!")
                        forceInterrupt = False
                        return
                    inFile = open(inFileName, "rb")
                except:
                    inFile = None
                    time.sleep(0.001)

            if inFile:
                i = 0;
                while True:
                    if utils.fileIsOver(inFile):
                        if maybeIsInSubprocess:
                            time.sleep(0.001)
                            continue
                        else:
                            self.writeChunk("Finished!")
                            # clean up
                            try:
                                if inFile: inFile.close()
                                os.remove(inFileName)
                            except:
                                pass
                            break
                    # read one symbol
                    c = inFile.read(1)
                    uploadLine += c
                    if c == '\n':
                        # if newline reached, print out the current line
                        self.writeChunk(uploadLine)
                        uploadLine = ""
                        i = i + 1
                        if i > limit:
                            break;
        except:
            raise
Ejemplo n.º 3
0
    def serveUploadResult(self, qs):
        global maybeIsInSubprocess
        global forceInterrupt

        self.send_response(200)
        self.sendDefaultHeaders()
        self.end_headers()

        inFileName = os.path.join("build", "child_output.txt")
        inFile = None

        try:
            limit = int(qs['line'][0])
        except:
            limit = 100000

        if limit == 1:
            # first time in this function
            maybeIsInSubprocess = True

        uploadLine = ""
        try:
            # wait until subprocess output file appears
            while inFile == None:
                try:
                    if forceInterrupt:
                        self.writeChunk("Finished!")
                        forceInterrupt = False
                        return
                    inFile = open(inFileName, "rb")
                except:
                    inFile = None
                    time.sleep(0.001)

            if inFile:
                i = 0
                while True:
                    if utils.fileIsOver(inFile):
                        if maybeIsInSubprocess:
                            time.sleep(0.001)
                            continue
                        else:
                            self.writeChunk("Finished!")
                            # clean up
                            try:
                                if inFile: inFile.close()
                                os.remove(inFileName)
                            except:
                                pass
                            break
                    # read one symbol
                    c = inFile.read(1)
                    uploadLine += c
                    if c == '\n':
                        # if newline reached, print out the current line
                        self.writeChunk(uploadLine)
                        uploadLine = ""
                        i = i + 1
                        if i > limit:
                            break
        except:
            raise