小编let*_*tsc的帖子

多处理:比cpu.count更多的进程

注意:我"潜入"了multiprocessing2天前的土地.所以我的理解非常基础.

我正在编写和上传到amazon s3存储桶的应用程序.在情况下,文件的大小较大(100mb),我已经实施并使用平行上传poolmultiprocessing模块.我使用一台机器core i7,我有一个cpu_count8.我的印象是,如果pool = Pool(process = 6)我使用6核心,文件开始上传部分,前6个部分的上传同时开始.为了看看当process大于时发生了什么cpu_count,我输入了20(意味着我想要使用20个核心).令我惊讶的是,程序开始同时上传20个零件而不是出现错误(我使用较小的部件chunk size以确保有大量零件).我不明白这种行为.我只有8核心,所以他的程序如何接受20的输入?当我说process=6,它实际上使用6个线程?这可能是20作为有效输入的唯一解释,因为可以有1000个线程.有人可以向我解释一下.

编辑:

我从这里借了'代码' .我只是略微改变了它,我要求用户选择核心用途,而不是设置parallel_processes为4

python multiprocessing

18
推荐指数
1
解决办法
8128
查看次数

如何在python 2.7中获取urllib2的状态代码

如何在python 2.7中获取urllib2的状态码?我不想使用请求.我需要urllib2.

    request = urllib2.Request(url, headers=headers)
    contents = urllib2.urlopen(request).read()
    print request.getcode()
    contents = json.loads(contents) 

     <type 'exceptions.AttributeError'>, AttributeError('getcode',), <traceback object at 0x7f6238792b48>
Run Code Online (Sandbox Code Playgroud)

谢谢

python

8
推荐指数
2
解决办法
2万
查看次数

如何使用 Boto 列出所有正在运行的 EMR 集群?

如何使用 boto 列出我的 aws 帐户中所有正在运行的集群?使用命令行我可以使用它们:

aws emr list-clusters --profile my-profile --region us-west-2 --active
Run Code Online (Sandbox Code Playgroud)

但是我想使用 boto3 做同样的事情。但是,以下代码不返回任何集群:

import boto3

session = boto3.Session(profile_name='my-profile')

client = session.client('emr', region_name= 'us-west-2')

response = client.list_clusters(
    ClusterStates=['RUNNING']
)

print response
Run Code Online (Sandbox Code Playgroud)

结果:

{u'Clusters': [], 'ResponseMetadata': {'RetryAttempts': 0, 'HTTPStatusCode': 200, 'RequestId': '577f3961-bdc80772f266', 'HTTPHeaders': {'x-amzn-requestid': '577f3961-34e5-11e7-a12a-bdc80772f266', 'date': 'Tue, 09 May 2017 18:28:47 GMT', 'content-length': '15', 'content-type': 'application/x-amz-json-1.1'}}}
Run Code Online (Sandbox Code Playgroud)

python amazon-web-services boto3

5
推荐指数
1
解决办法
6428
查看次数

Rabbitmq-队列状态显示为“正在运行”,GUI状态显示为“空闲”

我在玩Rabbitmq HTTP API时遇到了一个奇怪的情况。当我通过Web界面查看队列时,两个队列的状态都显示为IDLE。队列状态IDLE

但是,当我使用HTTP API时,两个队列的返回都显示为“正在运行”。即时通讯使用的代码如下:

import requests
import json

uri = 'http://localhost:15672/api/queues'

r = requests.get(uri, auth=("guest","guest"))

parsed = json.loads(r.content)
#print json.dumps(parsed, indent=4)
for i in parsed:
    print '{:<20} : {}'.format(i.get('name'), i.get('state'))
Run Code Online (Sandbox Code Playgroud)

输出:

test queue           : running
test2                : running
Run Code Online (Sandbox Code Playgroud)

有人可以向我解释这种行为吗?

python rabbitmq

4
推荐指数
1
解决办法
7372
查看次数

Terraform-资源重复多次

我有一个terraform计划,它由多个aws_sqs_queue资源组成,这些资源更多或更少地共享同一配置。在删除任何重复的配置并使用变量之前,我想运行terraform plan一下以查看其是否有效。但是我一直遇到-

module root: 1 error(s) occurred:

* data.template_file.ep_match_result_queues: resource repeated multiple times
Run Code Online (Sandbox Code Playgroud)

香港专业教育学院试图谷歌搜索,但没有太多可用信息。任何帮助都感激不尽。我的计划如下所示:(忽略多余的括号,错别字,因为这只是一个骨架,可以使您大致了解计划的结构):

data "template_file" "ep_match_result_queues" {
  template = "${var.namespace}-sm-ep"
}

resource "aws_sns_topic" "sns_topic_name" {
  name            = "ep_sm_match_result_topic${var.environment}"
  display_name    = ""
  policy          = <<POLICY
{
 #policy
}


resource "aws_sqs_queue" "queue1" {
 #config
}

resource "aws_sqs_queue" "queue2" {
 #config

    redrive_policy             = <<POLICY
{
 #policy
}
POLICY
}

resource "aws_sqs_queue" "queue3" {
#config
}

resource "aws_sqs_queue" "queue4" {
 #config

    redrive_policy             = <<POLICY
{
 #policy
}
POLICY
} …
Run Code Online (Sandbox Code Playgroud)

amazon-web-services terraform

4
推荐指数
1
解决办法
6263
查看次数

Terraform 条件变量

我的 terraform 配置中有一个模板,我在其中写入变量的值,如下所示:

data "template_file" "config" {
  template = "${file("${path.module}/templates/${var.json_config}")}"

  vars {
    is_enabled = "${var.is_enabled}"
  }
}
Run Code Online (Sandbox Code Playgroud)

Nowis_enabled是一个布尔字符串,设置为truefalse。现在,根据这是真还是假,我想设置另一个变量。在伪代码中它看起来像这样:

如果 is_enabled == true 路径 = /一个/路径/ 否则路径 = /另一个/路径

我看过了,conditional values但似乎是为了提供资源。我将如何使用它在模板文件中设置变量?

amazon-web-services terraform

3
推荐指数
1
解决办法
3462
查看次数

Python在列表中查找字符串

我有一个salt模块,它返回以下输出(我将所有这些存储到列表中以使迭代更容易):

    - 2015-05-21 19:25:08,060 [main] WARN  [::::::] c.p.core.FilteringPropertyPlaceholderConfigurer - Could not load properties from class path resource [proferi-component-test.properties]: class path resource [proferi-component-test.properties] cannot be opened because it does not exist
    - 2015-05-21 19:25:08,064 [main] WARN  [::::::] c.p.core.FilteringPropertyPlaceholderConfigurer - Could not load properties from class path resource [qe-prop-not-specified]: class path resource [qe-prop-not-specified] cannot be opened because it does not exist
    - 2015-05-21 19:25:13,290 [main] INFO  [::::::] c.p.a.m.persistence.modular.ModelSessionManager - Setup SessionManager modelSessionFactory
    - 2015-05-21 19:25:14,327 [main] INFO  [::::::] c.p.a.model.persistence.BlueprintsGraphReadSession - Loading model …
Run Code Online (Sandbox Code Playgroud)

python regex

1
推荐指数
1
解决办法
408
查看次数

Git rebase交互式错误

我想合并我的分支(让我们称之为my_branch)来掌握.它有一个文件在我的github.com上的pull请求中显示为合并冲突.在重新定位之前我想要压缩我的提交(11次提交).所以我做了这样的事情:

# On master
git pull
git checkout my_branch
# on my_branch
git fetch
git rebase -i origin/master
Run Code Online (Sandbox Code Playgroud)

这打开了一个vim编辑器,我的所有提交 - 我保留了第一个,pick并将其余部分更改为s (squash)

pick commit1
s commit2
s commit3
.
.
.
s commit 11
Run Code Online (Sandbox Code Playgroud)

当我保存并退出时,我收到错误 - error: could not apply e7ce468... 'commit1 message'

任何人都可以向我解释问题是什么?我知道我不能因为挤压而变废,因为每一次提交都需要解决.

git git-rebase git-squash

0
推荐指数
1
解决办法
895
查看次数