jackfrued / jackfrued/Python-100-Days
Day 13 - 进程和线程 - multiprocess1.py 无法结束
Nobody has claimed this yet.
- Dominant language
- Jupyter Notebook
- Stars
- 187k
- Forks
- 55.8k
- PR merge metrics
- No merged PRs in 30d
Description
对Python和对Github都是新手.
为免大家看得的不是同一份代码,全文引用如下
from multiprocessing import Process, Queue
from time import sleep
def sub_task(string, q):
number = q.get()
while number:
print('%d: %s' % (number, string))
sleep(0.001)
number = q.get()
def main():
q = Queue(10)
for number in range(1, 11):
q.put(number)
Process(target=sub_task, args=('Ping', q)).start()
Process(target=sub_task, args=('Pong', q)).start()
if name == 'main':
main()
然后无论是在pycharm里面还是命令行里,输出了总共10行的ping或者pong之后,都卡在那边永不结束了.可是我不理解这是为什么.两个进程中间共享一个Queue,queue里的东西取光了就完了呀,为啥这个还不结束退出呢
谢谢
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 multiprocessing example in multiprocess1.py and run the code shown in the issue from the command line. Inspect how the shared Queue is consumed and how the two Process instances are managed; done means the example's behavior and termination are explained or corrected so both processes exit after the ten items are processed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- operating-systems
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100