I would start first looking for a place to figure out at which time the memory gets full. The memory consumption can be monitored with an extra module psutil, which is a great cross-platform library for obtaining information on running processes and system utilization (i.e., CPU, memory, disks, network). I guess you could also use any other logging techniques in your code that Python has to control the memory use.
Another general thing you might want to try is to use a module subprocess; there is a great post on how to use this module here. You basically would try to spawn new processes, then connect to their pipes, and obtain their return codes.