jackfrued / jackfrued/Python-100-Days
day 13 通过Queue实现多进程简单通信
Open
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,Queue,set_start_method
from time import sleep
counter = 0
def sub_task(string,q):
a = q.get()
sleep(0.01)
while a < 10:
if q.empty():
q.put(a+1)
sleep(0.01)
print(string, end = '', flush=True)
a = q.get()
if q.empty():
q.put(a+1)
sleep(0.1)
return
def main():
#mac os 上运行会有错误
set_start_method('fork')
q = Queue()
q.put(0)
p1 = Process(target=sub_task,args=('ping',q))
p2 = Process(target=sub_task,args=('pong',q))
p1.start()
p2.start()
if __name__ == '__main__':
main()
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
Run the provided Python snippet on macOS, starting with main() and the set_start_method('fork') call, and capture the reported error. Check the Queue and Process interaction, with completion defined by the example running as intended on macOS or clearly documenting the platform limitation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- operating-systems
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100