mardi 29 avril 2014

python - arrêts de travail battu céleri échoue après quelques beats (opencv) - Stack Overflow


I have a celery task that runs on a beat every 60 seconds to grab a webcam, take a still from it, and then write it to a file so a server can serve it up on a webpage later. Image taking uses opencv via the cv2 library in python.


It looks like this:


    @app.task                               # a task to get and save a webcam image
def getWebCamImage()
logger.debug("capturing image attempt")
c = cv2.VideoCapture(0) #returns a videocapture object
flag, frame = c.read() #grabs and decodes the next frame
cv2.imwrite('file/loc/img.jpg, frame) #writes the frame to a file
logger.debug('saved image...hopefully')
c.release() #releases the videocapture object
return 0

Everything goes great for the first few minutes, but then it spits out the normal errors about not being able to get webcam properties and just stops. and it never starts again!


    ...DEBUG/BEAT] celerytest.getwebcamimage[process]:capturing image attempt
VIDOC_QUERYMENU:Invalid argument
VIDOC_QUERYMENU:Invalid argument
VIDOC_QUERYMENU:Invalid argument

This is exactly how it looks when it does work, only it keeps going. Any Idea what could be stopping it? I am running it on a rasperry pi with 240Mb dedicated to the arm core and 16 to graphics.


Things I have done to try to fix it:


    $sudo sysctl vm.overvommit_memory=1

So it doesent throw mem. allocation errors $sudo rmmod ucvideo $sudo modprobe ucvideo nodrop=1 timeout=5000 quirks=0x80 So the driver is more patient with the cam. I have tried a few cams, so that is likely not the issue.


Please help with whatever suggestions or tests you an think of. This is a tricky one because it is: on a pi, and is a pi/cellery cross. I am going to try just running a script with guvcview, but I feel a py/opencv option is cleaner because it is easier to install, and either way I would like to know why this doesn't work!


News:


DMESG reveals that a celery process is being killed because it is out of memory. Any way to fix this? How, if at all, are objects created in tasks destroyed?




This turned out to be unrelated to Celery, and related to cv.


If every time the CV2.videocapture object was released, it was not deleted, so the memory was still reserved. On the pi, which has very little memory, this quickly took up all the memory and was killed. I investigated memory usage with the top command in linux.


It happens on larger computers, but the symptoms were more severe on the pi.



I have a celery task that runs on a beat every 60 seconds to grab a webcam, take a still from it, and then write it to a file so a server can serve it up on a webpage later. Image taking uses opencv via the cv2 library in python.


It looks like this:


    @app.task                               # a task to get and save a webcam image
def getWebCamImage()
logger.debug("capturing image attempt")
c = cv2.VideoCapture(0) #returns a videocapture object
flag, frame = c.read() #grabs and decodes the next frame
cv2.imwrite('file/loc/img.jpg, frame) #writes the frame to a file
logger.debug('saved image...hopefully')
c.release() #releases the videocapture object
return 0

Everything goes great for the first few minutes, but then it spits out the normal errors about not being able to get webcam properties and just stops. and it never starts again!


    ...DEBUG/BEAT] celerytest.getwebcamimage[process]:capturing image attempt
VIDOC_QUERYMENU:Invalid argument
VIDOC_QUERYMENU:Invalid argument
VIDOC_QUERYMENU:Invalid argument

This is exactly how it looks when it does work, only it keeps going. Any Idea what could be stopping it? I am running it on a rasperry pi with 240Mb dedicated to the arm core and 16 to graphics.


Things I have done to try to fix it:


    $sudo sysctl vm.overvommit_memory=1

So it doesent throw mem. allocation errors $sudo rmmod ucvideo $sudo modprobe ucvideo nodrop=1 timeout=5000 quirks=0x80 So the driver is more patient with the cam. I have tried a few cams, so that is likely not the issue.


Please help with whatever suggestions or tests you an think of. This is a tricky one because it is: on a pi, and is a pi/cellery cross. I am going to try just running a script with guvcview, but I feel a py/opencv option is cleaner because it is easier to install, and either way I would like to know why this doesn't work!


News:


DMESG reveals that a celery process is being killed because it is out of memory. Any way to fix this? How, if at all, are objects created in tasks destroyed?



This turned out to be unrelated to Celery, and related to cv.


If every time the CV2.videocapture object was released, it was not deleted, so the memory was still reserved. On the pi, which has very little memory, this quickly took up all the memory and was killed. I investigated memory usage with the top command in linux.


It happens on larger computers, but the symptoms were more severe on the pi.


0 commentaires:

Enregistrer un commentaire