如何将对象与iterables一起传递给executor.map?

时间:2018-04-03 07:02:31

标签: python-3.x concurrency concurrent.futures map-function concurrent-processing

<div class="wrapper">
  <p class="text">bla blah some long text here try to resize</p>
</div>

.wrapper {
  background-color: #16b629;
  width: 80%;
  position: relative;
  left: 20%;
}

.wrapper::before {
  content: "";
  position: absolute;
  left: -23px;
  bottom: 0;

  width: 0;
  height: 0;
  border-style: solid;
  border-width: 0 0 46px 23px;
  border-color: transparent transparent #16b629 transparent;
  z-index: 999;
}

.text {
  padding: 10px 0;
  font-size: 21px;
  font-weight: bold;
  font-style: normal;
  font-stretch: normal;
  line-height: 1.27;
  letter-spacing: -0.2px;
  text-align: center;
  color: #ffffff;
  text-shadow: 0.5px 0.9px 2px rgba(27, 29, 27, 0.94);
}

这不起作用,因为executor.map函数没有将tFile对象传递给function.How我能解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

你有一个选择是创建一个长度为tFile len(file_list)的列表,这需要O(n)空间并且效率很低。

我这样使用itertools.repeat,因为它更节省空间,因为它是O(1):

with concurrent.futures.ProcessPoolExecutor() as executor:
    executor.map(function,file_list,itertools.repeat(tFile, len(file_list)))

itertools文档:

https://docs.python.org/3/library/itertools.html#itertools.repeat