Try to detect repetitive errors and sleep for a while to avoid being marked as spam
425515
def handle_error(self, error):
        
        logging.exception("try to sleep if there are repeating errors.")
        error_desc = str(error)
        now = datetime.datetime.now()
        if error_desc not in self.error_time_log:
            self.error_time_log[error_desc] = now
            return

        time_of_last_encounter = self.error_time_log[str(error)]
        time_since_last_encounter = now - time_of_last_encounter
        if time_since_last_encounter.total_seconds() > self.config.get('min_seconds_between_errors'):
            self.error_time_log[error_desc] = now
            return

        if error_desc not in self.error_sleep_log:
            time.sleep(self.config.get('sleep_seconds_on_consecutive_errors'))
            self.error_sleep_log[error_desc] = 1
        else:
            sys.exit()
440724
def checkError(barcode, whitelist, errors=1):
    '''
    
    '''

    near_matches = []
    comp_regex = regex.compile("(%s){e<=%i}" % (barcode, errors))
    b_length = len(barcode)
    for whitelisted_barcode in whitelist:
        w_length = len(whitelisted_barcode)

        # Don't check against itself
        if barcode == whitelisted_barcode:
            continue

        # If difference in barcode lengths > number of allowed errors, continue
        if (max(b_length, w_length) > (min(b_length, w_length) + errors)):
            continue
        if comp_regex.match(whitelisted_barcode):
            near_matches.append(whitelisted_barcode)

            # Assuming downstream processes are the same for
            # (>1 -> Inf) near_matches this is OK
            if len(near_matches) > 1:
                return near_matches

    return near_matches
916184
private static function catchError()
    {
        switch (json_last_error()) {
            case JSON_ERROR_NONE:
                self::$error = false;
                break;
            case JSON_ERROR_DEPTH:
                self::$error = 'Maximum stack depth exceeded';
                break;
            case JSON_ERROR_STATE_MISMATCH:
                self::$error = 'Underflow or the modes mismatch';
                break;
            case JSON_ERROR_CTRL_CHAR:
                self::$error = 'Unexpected control character found';
                break;
            case JSON_ERROR_SYNTAX:
                self::$error = 'Syntax error, malformed JSON';
                break;
            case JSON_ERROR_UTF8:
                self::$error = 'Malformed UTF-8 characters, possibly incorrectly encoded';
                break;
            default:
                self::$error = 'Unknown error';
                break;
        }
    }
854415
def background_thread():
    """"""
    count = 0
    while True:
        socketio.sleep(10)
        count += 1
        socketio.emit('my_response',
                      {'data': 'Server generated event', 'count': count},
                      namespace='/test')
887935
def watchdog(sleep_interval):
    
    mtimes = {}
    worker_process = restart_with_reloader()
    signal.signal(
        signal.SIGTERM, lambda *args: kill_program_completly(worker_process)
    )
    signal.signal(
        signal.SIGINT, lambda *args: kill_program_completly(worker_process)
    )
    while True:
        for filename in _iter_module_files():
            try:
                mtime = os.stat(filename).st_mtime
            except OSError:
                continue

            old_time = mtimes.get(filename)
            if old_time is None:
                mtimes[filename] = mtime
                continue
            elif mtime > old_time:
                kill_process_children(worker_process.pid)
                worker_process.terminate()
                worker_process = restart_with_reloader()
                mtimes[filename] = mtime
                break

        sleep(sleep_interval)
687898
def _error_check(err, prefix=""):
    """"""
    if err != 0:
        err_str = _snd.sf_error_number(err)
        raise RuntimeError(prefix + _ffi.string(err_str).decode('utf-8', 'replace'))
1249227
function detectResponseError(response) {
  if (response.statusCode && (response.statusCode < 200 || response.statusCode >= 300)) {
    return {
      status: response.statusCode,
      message: response.body || response.message || response
    }
  }
}
548466
def _error_is_suppressed(error, code, contents):
    """"""
    if len(contents) == 0:
        return False

    if error.line > 1:
        # Check above, and then to the side for suppressions
        above = contents[error.line - 2].split("#")
        if len(above) and _line_suppresses_error_code(above[-1].strip(),
                                                      code):
            return True

    aside = contents[error.line - 1].split("#")
    if len(aside) and _line_suppresses_error_code(aside[-1].strip(), code):
        return True

    return False
884349
def spam(user_ip, user_agent, params = {})
      response = invoke_comment_method('submit-spam',
        user_ip,
        user_agent,
        params)

      unless response.body == 'Thanks for making the web a better place.'
        raise_with_response response
      end
    end
1190767
function check() {
        if (done) {
          return;
        }
        checks--;
        if (checks <= 0) {
          return;
        }
        if (checks === 0) {
          done = true;
          finish(new Error('Machine unresponsive to STOP'));
          return;
        }
        var checkOptions = {
          method: 'GET',
          path: self.account + '/machines/' + serverId
        };

        self._request(checkOptions, function (err, body) {
          if (err) { return callback && callback(err) }
          if (body && body.state === 'stopped') {
            done = true;
            finish();
            return;
          }
        });

        setTimeout(check, 5000);
      }
775097
function checkSearchTerm(searchTerm){
		if (!is_string(searchTerm) && !is_numeric(searchTerm)){
			console.log('\nError: This must be either a string or an interval:\n', searchTerm, ' \n');
			return false;
		} else {
			return true;
		}
	}
1105053
public function request_is_spam()
    {
        $salt = $this->get_session_salt();

        $today_fieldname     = SecurityTool::get_today_fieldname($salt);
        $yesterday_fieldname = SecurityTool::get_yesterday_fieldname($salt);

        $is_spam = true;

        $today_fieldname_data     = $this->controller->getRequest()->getData($today_fieldname);
        $yesterday_fieldname_data = $this->controller->getRequest()->getData($yesterday_fieldname);

        if(!empty($today_fieldname_data) && $today_fieldname_data == $today_fieldname)
        {
            $is_spam = false;
        }
        elseif(!empty($yesterday_fieldname_data) && $yesterday_fieldname_data == $yesterday_fieldname)
        {
            $is_spam = false;
        }

        return $is_spam;
    }
359710
def maintenance_sleeper(api, response, sleep=300):
    
    while response.status_code == 503:
        logger.info('Service unavailable: Response=[%s]',
                    six.text_type(response.__dict__))
        response_body = response.json()
        if 'code' in response_body:
            if response_body['code'] == 0:
                logger.warning('API Maintenance in progress!'
                               ' Waiting for [%s]s', sleep)
                time.sleep(sleep)
                response = api.session.send(response.request)
            else:
                return response
        else:
            return response
    return response
829710
private function _process_paused() {

        // copy all requests to another variable
        $urls = $this->_requests;

        // while there are URLs to process
        while (!empty($urls)) {

            // get from the entire list of requests as many as specified by the "threads" property
            $this->_requests = array_splice($urls, 0, $this->threads, array());

            // process those requests
            $this->_process();

            // wait for as many seconds as specified by the "pause_interval" property
            if (!empty($urls)) sleep($this->pause_interval);

        }

    }
419296
def check_spam(self, ip=None, email=None, name=None, login=None, realname=None,
                   subject=None, body=None, subject_type='plain', body_type='plain'):
        
        data = {'ip': ip, 'email': email, 'name': name, 'login': login, 'realname': realname,
                'body-%s' % body_type: body, 'subject-%s' % subject_type: subject}
        r = self.request('post', 'http://cleanweb-api.yandex.ru/1.0/check-spam', data=data)
        root = ET.fromstring(r.content)
        return {
            'id': root.findtext('id'),
            'spam_flag': yesnobool(root.find('text').attrib['spam-flag']),
            'links': [(link.attrib['href'], yesnobool(link.attrib['spam-flag'])) for link in root.findall('./links/link')]
        }
79078
def alertingNetToMs(Facility_presence=0, ProgressIndicator_presence=0,
                    UserUser_presence=0):
    """"""
    a = TpPd(pd=0x3)
    b = MessageType(mesType=0x1)  # 00000001
    packet = a / b
    if Facility_presence is 1:
        c = FacilityHdr(ieiF=0x1C)
        packet = packet / c
    if ProgressIndicator_presence is 1:
        d = ProgressIndicatorHdr(ieiPI=0x1E)
        packet = packet / d
    if UserUser_presence is 1:
        e = UserUserHdr(ieiUU=0x7E)
        packet = packet / e
    return packet
740420
def on_message(self, message):
        """"""
        json_rpc = json.loads(message)
        logging.log(logging.DEBUG, json_rpc)

        if self.pool is None:
            self.pool = multiprocessing.Pool(processes=args.workers)

        # Spawn a process to protect the server against segfaults
        async = self.pool.apply_async(_worker_process, [json_rpc])
        try:
            result = async.get(timeout=args.timeout)
            error = 0
        except multiprocessing.TimeoutError:
            result = ("File format conversion timed out! This is due "
                      "either to a large input file or a segmentation "
                      "fault in the underlying open babel library.")
            error = 1
            self.pool.terminate()
            self.pool = multiprocessing.Pool(processes=args.workers)
        except Exception:
            result = traceback.format_exc()
            error = 1
        logging.log(logging.DEBUG, result)

        self.write_message(json.dumps({'result': result, 'error': error,
                                       'id': json_rpc['id']},
                                      separators=(',', ':')))