Example #1
0
    def report(self):
        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        while 1:
            time.sleep(2)
            prog = "mj:%d/%s\n wc:%d \n rc:%d" % (self._mjob_count, self._mjob_all, self._worker_count, self._running_count)
            if isinstance(self.cur_jobid, dict) and 'url' in self.cur_jobid:
                cjstr = util.utf8str(self.cur_jobid['url'])
            else:
                cjstr = util.utf8str(self.cur_jobid)
            cjstr = re.sub(r'\r|\n', '', cjstr)
            if len(cjstr) > 100:
                cjstr = cjstr[0:100]

            message = "[pid=%d]job:%s prog:%s\n" % (os.getpid(), cjstr, prog)
            try:
                s.sendto(message, ("127.0.0.1", self._log_port))
            except Exception as e:
                pass
            if self._end_mark:
                message = "[pid=%d] DONE\n" % (os.getpid())
                try:
                    s.sendto(message, ("127.0.0.1", self._log_port))
                except:
                    pass
                return
Example #2
0
def csv_write_c(csv_file, header, value):
    check_csv_head(csv_file, header)

    row = []
    for k in header:
        v = value.get(k, '')
        row.append(utf8str(v))

    print row
    csv_file.append_row(row)