jackfrued / jackfrued/Python-100-Days

Day13多进程下载案例问题

Open
#249 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Jupyter Notebook
Stars
187k
Forks
55.8k
PR merge metrics
No merged PRs in 30d

Description

from multiprocessing import Process
from os import getpid
from random import randint
from time import time, sleep


def download_task(filename):
    print('启动下载进程,进程号[%d].' % getpid())
    print('开始下载%s...' % filename)
    time_to_download = randint(5, 10)
    sleep(time_to_download)
    print('%s下载完成! 耗费了%d秒' % (filename, time_to_download))


def main():
    start = time()
    p1 = Process(target=download_task, args=('Python从入门到住院.pdf', ))
    p1.start()
    p2 = Process(target=download_task, args=('Peking Hot.avi', ))
    p2.start()
    p1.join()
    p2.join()
    end = time()
    print('总共耗费了%.2f秒.' % (end - start))

if __name__ == '__main__':
     main()

这个案例在Windows 10 1809下的jupyter notebook中永远只打印输出:

总共耗费了0.XX秒.

但是这段代码单独保存为.py文件运行后可以得到正确的结果,请问这是Windows的问题还是Jupyter notebook的问题呢?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the multiprocessing example shown in the issue and compare its behavior in a Windows 10 Jupyter Notebook with the same code run as a .py file. Investigate how the notebook starts child processes and verify whether the child-process output is suppressed or the execution context differs. Done means identifying whether the cause is Windows, Jupyter Notebook, or their interaction and documenting a reproducible explanation.

Written by the indexing model from the issue text.

Assessment

Tech stack
jupyter-notebook, python
Domain
devtools, operating-systems
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.