python_basic_11 (零基础---socket基本使用)

适合零基础学习的—关于多任务-进程的简单练习:

"""
给process传参
"""

def test1(a, b, c, *args, **kwargs):
    print(a)
    print(b)
    print(c)
    print(args)
    print(kwargs)


def main():
    print("--in 主进程 pid=%d 父进程 ppid = %d" % (os.getpid(), os.getppid()))
    p = multiprocessing.Process(target=test1, args=(11, 22, 33, 44, 55, 66, 77, 88),kwargs= {"mm":11})
    p.start()


if __name__ == '__main__':
    main()



"""
进程间不共享全局变量
"""

nums = [11, 22, 33]


def test1():
    """子进程1"""
    nums.append(44)
    print("在进程中1中nums = %s" % str(nums))
    time.sleep(1)


def test2():
    """子进程2"""
    print("在进程中2中nums = %s" % str(nums))


def main():
    print("--in 主进程 pid=%d 父进程 ppid = %d" % (os.getpid(), os.getppid()))
    p = multiprocessing.Process(target=test1)
    p.start()

    time.sleep(1)
    p2 = multiprocessing.Process(target=test2)
    p2.start()


if __name__ == '__main__':
    main()

猜你喜欢

转载自blog.csdn.net/weixin_44786482/article/details/89913797
今日推荐