Message 321088 - Python tracker

Message321088

Author Windson Yang
Recipients Windson Yang, docs@python
Date 2018-07-05.08:45:49
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1530780349.49.0.56676864532.issue34051@psf.upfronthosting.co.za>
In-reply-to
Content
The docs at https://docs.python.org/3.8/library/multiprocessing.html#synchronization-between-processes give an example:

from multiprocessing import Process, Lock

def f(l, i):
    l.acquire()
    try:
        print('hello world', i)
    finally:
        l.release()

if __name__ == '__main__':
    lock = Lock()

    for num in range(10):
        Process(target=f, args=(lock, num)).start()

and point out "For instance one can use a lock to ensure that only one process prints to standard output at a time...". I'm not sure this is a good enough example for the reader. The reader can't tell the difference between the function with l.acquire() or not, The output just shows in the terminal at the same time. So I think a better idea just add time.sleep(0.1) before print('hello world', i) like this:

    l.acquire()
    try:
        # do something here
        # time.sleep(0.1)
        print('hello world', i)

I can provide a pr if you guys like this idea.
History
Date User Action Args
2018-07-05 08:45:49Windson Yangsetrecipients: + Windson Yang, docs@python
2018-07-05 08:45:49Windson Yangsetmessageid: <1530780349.49.0.56676864532.issue34051@psf.upfronthosting.co.za>
2018-07-05 08:45:49Windson Yanglinkissue34051 messages
2018-07-05 08:45:49Windson Yangcreate