0

It is a bit hard to show and ask to review entire code, so please let me describe it. I am using Rpi as serial-controller with python script but the python script become frozen.(technically I have to my headless Rpi again) I only guess this is somehow memory issue with my script and I understand there is so many parameters make it happen, but I have really no idea where to start to fix it. Or work-around..

1.

I wonder if there is any way to diagnosis the problem? I tried to count object within loop gc but it shows always stable count, so seems not caused by anything relevant with this.

current_num_objects = len(gc.get_objects())
new_objects = current_num_objects - previous_num_objects

del rec_p0, rec_p1

#gc.collect() # still makes problem
print "#####    BLOCK TIME = ", time.time()-ini_time, " #####", block_t[0], block_t[1]
ini_time=time.time()

#re.purge()
print "(%d) This: %d, New: %d, Garbage: %d, Collection Counts: %s"\

% (rgb, current_num_objects, new_objects, len(gc.garbage), gc.get_count()) previous_num_objects = current_num_objects

2.

In my situation, the script has to run continuously for a day. The core script has to run every 20~30 seconds. Is there proper way to make infinite loop to avoid memory issue?

3.

within loop, I am using multiprocessing and threading with audio streams. I am aware that it should be very carefully designed to work with thread/multiprocessing, so I made every process/thread should be .join() before to proceed next loop cycle.

Still I am kind of suspicious if they return memory immediately or closing process for sure. Probably slow closing or .join() process accumulating time and occupying resources that could make it problem? For example I've noticed open/close audio stream needs enough delay time to access device again.(it could be depends on sounddevice though) In those cases, time.sleep() will any help?

4. My script use software-serial communication(pigpio) while processing audio stream(PyAudio-sounddevice module). I have no idea about its internal logic but I wonder if it is more cache problem rather than memory issue?(I even don't know if I have to consider these separately. Should I?)

  • When I see process status with another session with 'nmon', python's PID and SIZE seems not really unusual. – YJL Aug 23 at 9:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.