Forums

OSError: [Errno 2] No such or directory and OSError: [Errno 12] Cannot allocate memory

I am trying to convert video with Apache Kafka and FFmpeg. I have run my program on my system, but it fails when it runs on the server. I run code I got this error:

Traceback (most recent call last):
  File "/home/fu/kafka/kafkaVideo/ffmpeg-python-master/ffmpeg/send.py", line 30, in <module>
    subprocess.call([sys.executable, start])
  File "/usr/lib/python2.7/subprocess.py", line 523, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/lib/python2.7/subprocess.py", line 711, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1235, in _execute_child
    self.pid = os.fork()
OSError: [Errno 12] Cannot allocate memory
frame send
frame send
frame send
frame send
...
raceback (most recent call last):
  File "/home/fu/kafka/kafkaVideo/ffmpeg-python-master/ffmpeg/send.py", line 30, in <module>
    subprocess.call([sys.executable, start])
  File "/usr/lib/python2.7/subprocess.py", line 523, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/lib/python2.7/subprocess.py", line 711, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1235, in _execute_child
    self.pid = os.fork()
OSError: [Errno 12] Cannot allocate memory
frame send
frame send
...
Traceback (most recent call last):
  File "send.py", line 107, in <module>
    publish_video(video_path)
  File "send.py", line 48, in publish_video
    subprocess.call([sys.executable, start])
  File "/usr/lib/python2.7/subprocess.py", line 523, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/lib/python2.7/subprocess.py", line 1392, in wait
    pid, sts = _eintr_retry_call(os.waitpid, self.pid, 0)
  File "/usr/lib/python2.7/subprocess.py", line 476, in _eintr_retry_call
    return func(*args)``
OSError: [Errno 2] No such or directory

but The third part of the error is different in different debug

[edit by admin: formatting]

Perhaps you're hitting the memory limit? The maximum amount of memory you can use on PythonAnywhere is 3GiB.

But code runs on my system. I think end of error is problem( OSError: [Errno 2] No such or directory ). what do you think about this?

sounds like you are hitting the memory limit, and so certain processes aren't able to run, and therefore no file was created, and then finally you are unable to find that file.

why don't you add some more debugging to try to figure out if that is the case? eg: which file is this, and which line of code is supposed to create this file.

this:

import sys
import time
import cv2
import ffmpeg._filters

from kafka import KafkaProducer

import os
import subprocess

mypath = os.path.abspath(__file__)
mydir = os.path.dirname(mypath)
start = os.path.join(mydir, "send.py")
subprocess.call([sys.executable, start])


DEFAULT_NUMNODES=10

topic = "distributed-video1"

def publish_video(video_file):

    producer = KafkaProducer(bootstrap_servers='localhost:9092')

    video = cv2.VideoCapture(video_file)

    mypath = os.path.abspath(__file__)
    mydir = os.path.dirname(mypath)
    start = os.path.join(mydir, "send.py")
    subprocess.call([sys.executable, start])

    split = ffmpeg.input(video_file).filter_multi_output('split')
    split0 = split.stream(0)
    split1 = split[1]

    ffmpeg.concat(split0, split1).output('out.mp4').run()

    while(video.isOpened()):
        success, frame = video.read()

        if not success:
            break

        time.sleep(0.2)
    video.release()
    print('publish complete')

def publish_camera():


    producer = KafkaProducer(bootstrap_servers='localhost:9092')

    mypath = os.path.abspath(__file__)
    mydir = os.path.dirname(mypath)
    start = os.path.join(mydir, "send.py")
    subprocess.call([sys.executable, start])

    split = ffmpeg.input(video_file).filter_multi_output('split')
    split0 = split.stream(0)
    split1 = split[1]

    ffmpeg.concat(split0, split1).output('out.mp4').run()

    camera = cv2.VideoCapture(0)
    try:
        while(True):
            success, frame = camera.read()

            ret, buffer = cv2.imencode('.jpg', frame)
            producer.send(topic, buffer.tobytes())


            time.sleep(0.2)

    except:
        print("\nExiting.")
        sys.exit(1)


    camera.release()


if __name__ == '__main__':

    if(len(sys.argv) > 1):
        video_path = sys.argv[1]

        publish_video(video_path)
    else:
        print("frame send")

Why don't you add some more debugging to try to figure out if that is the case? eg: which file is missing, and which line of code is supposed to create this file. And if that line of code failed, is it failing when you see the error about not being able to get more memory?