python progressbar 多行_使用单击.progressbar在Python中使用多处理

我有一个巨大的列表,我需要处理,这需要一些时间,所以我把它分为4个部分,并用一些函数对每个部分进行多重处理。用4个内核运行仍然需要一些时间,所以我想我应该在函数中添加一些进度条,这样它就可以告诉我每个处理器在处理列表时的位置。在

我的梦想是拥有这样的东西:erasing close atoms, cpu0 [######..............................] 13%

erasing close atoms, cpu1 [#######.............................] 15%

erasing close atoms, cpu2 [######..............................] 13%

erasing close atoms, cpu3 [######..............................] 14%

随着函数中循环的进行,每个条都在移动。但是我得到了一个连续的

5a7e7afbb6d5021e7bf6af3b313b211f.png

等等,填满了我的终端窗口。在

下面是调用函数的主要python脚本:

^{pr2}$

下面是函数eraseCloseAtoms():import numpy as np

import click

def eraseCloseAtoms(protein, atoms, cell, spacing=2, dmin=1.4, output=None):

print 'just need to erase close atoms'

if dmin > spacing:

print 'the spacing needs to be larger than dmin'

return

grid = [int(cell[0] / spacing), int(cell[1] / spacing), int(cell[2] / spacing)]

selected = list(atoms)

with click.progressbar(length=len(atoms), label='erasing close atoms') as bar:

for i, atom in enumerate(atoms):

bar.update(i)

erased = False

coord = np.array(atom[6])

for ix in [-1, 0, 1]:

if erased:

break

for iy in [-1, 0, 1]:

if erased:

break

for iz in [-1, 0, 1]:

if erased:

break

for j in protein:

protCoord = np.array(protein[int(j)][6])

trueDist = getMinDist(protCoord, coord, cell, vectors)

if trueDist <= dmin:

selected.remove(atom)

erased = True

break

if output is None:

return selected

else:

output.put(selected)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值