UnboundLocalError:分配前已引用局部变量“ retry_rdd”

时间:2019-06-07 04:12:31

标签: python python-3.x

在分配python错误之前引用了本地变量'retry_rdd'

我尝试将其引用为全局变量,但仍给出了名称  未定义的错误。

    def send_message(self, df):
        #global retry_rdd
        try:

            results_rdd.cache()
            logger.info("Count of the list in rdd = " + str(results_rdd.count()))

            error_rdd = results_rdd.filter(lambda x: '(numbers_sent,messages_sent)' not in x)
            logger.info(error_rdd.count())

            retry_rdd = error_rdd.mapPartitions(
                lambda part: self.retrySend_msg(part, config, token))
            retry_rdd.cache()

        except Exception as e:
            logger.error("Error occurred while sending to dest.")
            logger.error(e)

        if retry_rdd and retry_rdd.count() > 0:
            error_archive = '{}/{}/'.format(self.config['error']['process'], self.get_time())

            logger.info("Saving errors to archive: {}".format(error_archive))
            retry_rdd.saveAsTextFile(error_archive)

0 个答案:

没有答案