jackfrued / jackfrued/Python-100-Days
Day13最后一个例子感觉计时部分不太对啊。。计时前是不是线程就已经开始启动了?
Open
Nobody has claimed this yet.
- Dominant language
- Jupyter Notebook
- Stars
- 187k
- Forks
- 55.8k
- PR merge metrics
- No merged PRs in 30d
Description
如下,如果我简单改下流程,让start后sleep5秒,实际计算时间就成0.08秒了,这显然不对吧。。
from multiprocessing import Process
from time import time, sleep
def task_handler():
sleep(5)
def main():
processes = []
# 启动8个进程将数据切片后进行运算
for _ in range(8):
p = Process(target=task_handler)
processes.append(p)
p.start()
# 开始记录所有进程执行完成花费的时间
sleep(5)
start = time()
for p in processes:
p.join()
end = time()
print('Execution time: ', (end - start), 's', sep='')
if __name__ == '__main__':
main()
Execution time: 0.08439040184020996s
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Day13 multiprocessing example shown in the issue and inspect where process startup, sleep, timing, and join are ordered. Verify the measured interval against the workers' actual runtime. Done means the lesson explains or corrects the timing measurement so it reflects the intended process execution.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- documentation
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100