Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 大容量数据插入期间使用django的MemoryError_Mysql_Django_Memory - Fatal编程技术网

Mysql 大容量数据插入期间使用django的MemoryError

Mysql 大容量数据插入期间使用django的MemoryError,mysql,django,memory,Mysql,Django,Memory,我有一个django应用程序在Linux机器上运行。此应用程序使用MySQL数据库,其中包含超过40000名雇主的列表。 我有一个django管理命令,它遍历雇主列表,并为每个雇主下载和插入其雇员的数据库。有些雇主的雇员不到100人,但有些雇主有数千人。因此,我们谈论的是大量数据 当我运行这个命令时,一切似乎都正常工作,直到在某个时刻(大约一小时后)我得到一个MemoryError。我不知道我在哪里泄漏内存。这是我的密码: import urllib3 class API: @stat

我有一个django应用程序在Linux机器上运行。此应用程序使用MySQL数据库,其中包含超过40000名雇主的列表。
我有一个django管理命令,它遍历雇主列表,并为每个雇主下载和插入其雇员的数据库。有些雇主的雇员不到100人,但有些雇主有数千人。因此,我们谈论的是大量数据

当我运行这个命令时,一切似乎都正常工作,直到在某个时刻(大约一小时后)我得到一个MemoryError。我不知道我在哪里泄漏内存。这是我的密码:

import urllib3

class API:
    @staticmethod
    def getEmployees(employer):

        employees = []

        url = 'someapiurl'
        http_pool = urllib3.connection_from_url(url)
        req = http_pool.get_url(url)

        #this parsing takes between 0.1 to 5 seconds, depending on the size of the response
        doc = xml.dom.minidom.parseString(req.data)

        nodes = doc.getElementsByTagName(MATCHING_ELEMENTS)

        for node in nodes:
            employee = Employee()
            employee.createDataFromNode(node)
            employees.append(employee)

        return employee


class SomeClass:
    #only commit on success - this is to prevent commits from happening every single time save() is called.  

    @transcation.commit_on_success
    @staticmethod
    def createAll():
        #there are over 40,000 employers
        for employer in Employers.objects.all():
            SomeClass.createEmployeesForEmployer(employer)

    @staticmethod
    def createEmployeesForEmployer(employer):
        employees = API.getEmployees(employer)
        for employee in employees:
                employee.save()

这里有什么问题?谢谢大家!

你能粘贴完整的堆栈跟踪吗?你的服务器上有调试关闭吗?嗨-不,我的调试打开了。这可能是原因吗?@Aldarund你的评论救了我一命!谢谢你能粘贴完整的堆栈跟踪吗?你的服务器上有调试关闭吗?嗨-不,我的调试打开了。这可能是原因吗?@Aldarund你的评论救了我一命!谢谢