# Path: datarobot_batch_scoring/consts.py
# SENTINEL = Batch(-1, 0, None, '', -1)
# 
# class WriterQueueMsg(object):
#     CTX_WARNING = 'CTX_WARNING'
#     CTX_ERROR = 'CTX_ERROR'
#     RESPONSE = 'RESPONSE'
#     SENTINEL = 'SENTINEL'
# 
# class ProgressQueueMsg(object):
#     SHOVEL_DONE = 'SHOVEL_DONE'
#     SHOVEL_ERROR = 'SHOVEL_ERROR'
#     SHOVEL_CSV_ERROR = 'SHOVEL_CSV_ERROR'
#     SHOVEL_PROGRESS = 'SHOVEL_PROGRESS'
#     NETWORK_DONE = 'NETWORK_DONE'
#     NETWORK_ERROR = 'NETWORK_ERROR'
#     NETWORK_PROGRESS = 'NETWORK_PROGRESS'
#     WRITER_DONE = 'WRITER_DONE'
#     WRITER_ERROR = 'WRITER_ERROR'
#     WRITER_PROGRESS = 'WRITER_PROGRESS'
# 
# REPORT_INTERVAL = 5
# 
# Path: datarobot_batch_scoring/utils.py
# def get_rusage():
#     usage = resource.getrusage(resource.RUSAGE_SELF)
#     return {
#         "utime": usage.ru_utime,
#         "stime": usage.ru_stime,
#         "rss": usage.ru_maxrss,
#     }
# 
# Path: datarobot_batch_scoring/exceptions.py
# class ShelveError(Exception):
#     pass
# 
# class UnexpectedKeptColumnCount(Exception):
#     pass
# 
# class NoPredictionThresholdInResult(Exception):
#     pass


import csv
import glob
import hashlib
import multiprocessing
import operator
import os
import shelve
import signal
import sys
import six
    import dbm.dumb as dumb_dbm
    import dumbdbm as dumb_dbm
from functools import reduce
from time import time
from six.moves import queue
from datarobot_batch_scoring.consts import SENTINEL, \
    WriterQueueMsg, ProgressQueueMsg, REPORT_INTERVAL
from datarobot_batch_scoring.utils import get_rusage
from datarobot_batch_scoring.exceptions import ShelveError, \
    UnexpectedKeptColumnCount, NoPredictionThresholdInResult

        """Process a successful request. """
        self._ui.debug('Writer Process started - {}'
                       ''.format(multiprocessing.current_process().name))

        rows_done = sum(rows for _, rows in self.ctx.db['checkpoints'])

        success = False
        processed = 0
        written = 0
        idle_cycles = 0
        last_report = time()

        try:
            while True:
                if self.abort_flag.value or self.local_abort_flag:
                    self._ui.debug('abort requested')
                    break
                try:
                    if idle_cycles > 2:
                        self.writer_status.value = b"I"
                    else:
                        self.writer_status.value = b"G"
                    msg, args = self.writer_queue.get(timeout=1)
                except queue.Empty:
                    idle_cycles += 1
                    continue
                idle_cycles = 0
                self.writer_status.value = b"W"


# Path: datarobot_batch_scoring/consts.py
# SENTINEL = Batch(-1, 0, None, '', -1)
# 
# class WriterQueueMsg(object):
#     CTX_WARNING = 'CTX_WARNING'
#     CTX_ERROR = 'CTX_ERROR'
#     RESPONSE = 'RESPONSE'
#     SENTINEL = 'SENTINEL'
# 
# class ProgressQueueMsg(object):
#     SHOVEL_DONE = 'SHOVEL_DONE'
#     SHOVEL_ERROR = 'SHOVEL_ERROR'
#     SHOVEL_CSV_ERROR = 'SHOVEL_CSV_ERROR'
#     SHOVEL_PROGRESS = 'SHOVEL_PROGRESS'
#     NETWORK_DONE = 'NETWORK_DONE'
#     NETWORK_ERROR = 'NETWORK_ERROR'
#     NETWORK_PROGRESS = 'NETWORK_PROGRESS'
#     WRITER_DONE = 'WRITER_DONE'
#     WRITER_ERROR = 'WRITER_ERROR'
#     WRITER_PROGRESS = 'WRITER_PROGRESS'
# 
# REPORT_INTERVAL = 5
# 
# Path: datarobot_batch_scoring/utils.py
# def get_rusage():
#     usage = resource.getrusage(resource.RUSAGE_SELF)
#     return {
#         "utime": usage.ru_utime,
#         "stime": usage.ru_stime,
#         "rss": usage.ru_maxrss,
#     }
# 
# Path: datarobot_batch_scoring/exceptions.py
# class ShelveError(Exception):
#     pass
# 
# class UnexpectedKeptColumnCount(Exception):
#     pass
# 
# class NoPredictionThresholdInResult(Exception):
#     pass


# Path: datarobot_batch_scoring/writer.py
import csv
import glob
import hashlib
import multiprocessing
import operator
import os
import shelve
import signal
import sys
import six
    import dbm.dumb as dumb_dbm
    import dumbdbm as dumb_dbm
from functools import reduce
from time import time
from six.moves import queue
from datarobot_batch_scoring.consts import SENTINEL, \
    WriterQueueMsg, ProgressQueueMsg, REPORT_INTERVAL
from datarobot_batch_scoring.utils import get_rusage
from datarobot_batch_scoring.exceptions import ShelveError, \
    UnexpectedKeptColumnCount, NoPredictionThresholdInResult


        """Process a successful request. """
        self._ui.debug('Writer Process started - {}'
                       ''.format(multiprocessing.current_process().name))

        rows_done = sum(rows for _, rows in self.ctx.db['checkpoints'])

        success = False
        processed = 0
        written = 0
        idle_cycles = 0
        last_report = time()

        try:
            while True:
                if self.abort_flag.value or self.local_abort_flag:
                    self._ui.debug('abort requested')
                    break
                try:
                    if idle_cycles > 2:
                        self.writer_status.value = b"I"
                    else:
                        self.writer_status.value = b"G"
                    msg, args = self.writer_queue.get(timeout=1)
                except queue.Empty:
                    idle_cycles += 1
                    continue
                idle_cycles = 0
                self.writer_status.value = b"W"


                if msg == WriterQueueMsg.CTX_ERROR: