Python 运行注释掉的代码
Posted
技术标签:
【中文标题】Python 运行注释掉的代码【英文标题】:Python runs the commented-out code 【发布时间】:2017-02-28 10:24:39 【问题描述】:我有一个问题,有时docker-py
返回错误:
Permission denied.
我正在尝试修复它。我将这段代码注释掉,收到如下图。
File "/opt/dst/src/utils/runner.py", line 48, in run_code
\#if len(cli.containers(filters='status': ['running', 'created'])) >= settings.DOCKER_CONTAINER_COUNT:
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'])) >= 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'))
runner.pyc 文件已更新。 可能是什么问题呢? 谢谢你的帮助,对不起我的英语不好
更新:
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'])) >= 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)
【问题讨论】:
如果删除注释掉的代码并运行它会发生什么,那么它可以正常工作吗? 请在您注释掉的那一行提供几行代码的代码块 从内存python 3这样解释cmets""" comment"""
,单行注释就是你需要的#comment
(你保存了吗?),你的jf条件是否超过80
字符?尝试用 ` \ ` 将其分成两行,然后注释这两行
添加代码行围绕导致错误的块,否则我们都只会坐在这里猜测而无法来帮你。或者,请添加您的完整代码。
【参考方案1】:
由于脚本出错,工作了两个实例celery,在运行实例过程中出现了这个错误,谁用过旧代码。
【讨论】:
以上是关于Python 运行注释掉的代码的主要内容,如果未能解决你的问题,请参考以下文章
ruby will_paginate(3.0.7)自定义渲染器。注释掉的代码是此版本gem的默认代码。使用`super`作为写的贝尔
已部署的 Web 应用程序仍会在 Chrome javascript 控制台 Flutter 中打印所有注释掉的打印语句