Python Process中的多个批量更新

时间:2018-08-06 12:07:26

标签: python django django-models multiprocessing

我正在5个表格中进行批量更新。这需要很多时间。因此,我决定使用python多处理Process对象并行执行此操作。这是我的代码:

    def bulk_insert_syllabus_data_parallely(self, data_to_insert):
    syllabus_log.info('inside parallely method')
    # inserts data using multiprocessing
    try:
        processes = []
        for key, value in data_to_insert.iteritems():
            processes.append(multiprocessing.Process(target=bulk_insert_data, args=(key, value)))

        for p in processes:
            p.start()

        for p in processes:
            p.join()
    except Exception, e:
        syllabus_log.info('Exception=-----%s' % e)

def bulk_insert_data(key, value):
try:
    syllabus_log.info('inside insert data-----%s' % key)
    if key == 'subjects':
        Table1.objects.bulk_create(value)
    elif key == 'chapters':
        Table2.objects.bulk_create(value)
    elif key == 'goals':
        Table3.objects.bulk_create(value)
    elif key == 'los':
        Table4.objects.bulk_create(value)
    elif key == 'tus':
        Table5.objects.bulk_create(value)
    syllabus_log.info('Successfully inserted0------%s' % key)
except Exception, e:
    log.info('Exception-----%s' % e)
    log.info('Exception-----%s' % key)

我收到此异常,只有1个过程成功。异常是SSL错误:解密失败或Mac记录错误或SSL SYSCALL错误:检测到EOF。为何在此问题以及如何解决?

表结构:

class TableA(models.Model):
s = models.ForeignKey('S')
s1 = models.ForeignKey('T', related_name='s_s1')
sequence = models.IntegerField(db_index=True)
status = models.CharField(default='hidden', max_length=255, db_index=True)
modified_at = models.DateTimeField(auto_now=True)
created_at = models.DateTimeField(auto_now_add=True)

0 个答案:

没有答案