Python runs the commented-out code
<p>I have a problem that sometimes <code>docker-py</code> returns an error:</p>

<pre><code>Permission denied.
</code></pre>

<p>I'm trying to fix it. I commented out the piece of code, and received the following picture.</p>

<pre><code>File "/opt/dst/src/utils/runner.py", line 48, in run_code

\#if len(cli.containers(filters={'status': ['running', 'created']})) &gt;= settings.DOCKER_CONTAINER_COUNT:
</code></pre>

<pre class="lang-html prettyprint-override"><code>Traceback (most recent call last):
  File "/opt/dst/env/lib/python2.7/site-packages/celery/app/trace.py", line 240, in trace_task
    R = retval = fun(*args, **kwargs)
  File "/opt/dst/env/lib/python2.7/site-packages/celery/app/trace.py", line 438, in __protected_call__
    return self.run(*args, **kwargs)
  File "/opt/dst/src/core/tasks.py", line 12, in run
    return 'Solution not found'
  File "/opt/dst/src/utils/runner.py", line 48, in run_code
    #if len(cli.containers(filters={'status': ['running', 'created']})) &gt;= settings.DOCKER_CONTAINER_COUNT:
  File "/opt/dst/env/lib/python2.7/site-packages/docker/api/container.py", line 85, in containers
    res = self._result(self._get(u, params=params), True)
  File "/opt/dst/env/lib/python2.7/site-packages/docker/utils/decorators.py", line 47, in inner
    return f(self, *args, **kwargs)
  File "/opt/dst/env/lib/python2.7/site-packages/docker/client.py", line 132, in _get
    return self.get(url, **self._set_request_timeout(kwargs))
  File "/opt/dst/env/lib/python2.7/site-packages/requests/sessions.py", line 487, in get
    return self.request('GET', url, **kwargs)
  File "/opt/dst/env/lib/python2.7/site-packages/requests/sessions.py", line 475, in request
    resp = self.send(prep, **send_kwargs)
  File "/opt/dst/env/lib/python2.7/site-packages/requests/sessions.py", line 585, in send
    r = adapter.send(request, **kwargs)
  File "/opt/dst/env/lib/python2.7/site-packages/requests/adapters.py", line 453, in send
    raise ConnectionError(err, request=request)
ConnectionError: ('Connection aborted.', error(13, 'Permission denied'))
</code></pre>



<p>The runner.pyc file is updated.
What could be the problem?
Thank you for your help and sorry for my bad english</p>

<p>UPDATE:</p>

<pre><code>cli = Client('unix://var/run/docker.sock', version='1.19')
kill_client = Client('unix://var/run/docker.sock', version='1.19', timeout=0.5)
config = cli.create_host_config(**get_host_config(file_path))
#if len(cli.containers(filters={'status': ['running', 'created']})) &gt;= settings.DOCKER_CONTAINER_COUNT:
#    return 'must retry', None
run_string = 'timeout {} python /tmp/script.py'.format(settings.DOCKER_EXECUTE_TIME)
container = cli.create_container('python:2', run_string, user=uid, host_config=config)
</code></pre>

<p>Due to an error in the script, worked two instance celery and this error occurred during the operation instance, who has worked with the old code.</p>

python django docker celery