python进程&线程
来源:互联网 发布:tensorflow有趣的项目 编辑:程序博客网 时间:2024/05/16 11:28
# -*- coding:UTF-8 -*-'''Created on 2015年10月25日@author: young'''import osimport threadingimport timeprint '多进程创建'print 'Process (%s) start...' % os.getpid()s=1111;pid = os.fork()if pid==0: s=222 print 'I am child process (%s) and my parent is %s.' % (os.getpid(), os.getppid()) else: s=333 print 'I (%s) just created a child process (%s).' % (os.getpid(), pid) print sprint '创建跨平台的多进程'from multiprocessing import Processimport os #子进程要执行的代码'def run_proc(name): print 'Run child process %s (%s)...' % (name, os.getpid())print 'Parent process %s.' % os.getpid()p = Process(target=run_proc, args=('test',))print 'Process will start.'p.start()p.join()print 'Process end.' print '###########多线程#################'def task(): print "%s is running "% (threading.current_thread().name,) for i in range(5): print "%s --> %d"%(threading.current_thread().name,i) time.sleep(1)#暂停1秒 print "%s end..." % (threading.current_thread().name,) print "%s is running "% (threading.current_thread().name,) th=threading.Thread(target=task,name="new thread")th.start()th.join()#加入到主线程中,等子线程结束后再结束主线程print "%s end..." % (threading.current_thread().name,)print '###################'
0 0
- python 进程和线程
- python进程和线程
- python进程&线程
- Python进程和线程
- Python 进程与线程
- python 线程与进程
- Python 线程和进程
- python线程、进程
- Python线程进程
- Python 线程、进程、协程
- Python进程、线程、协程
- python 线程与进程
- python 进程和线程
- python中的进程, 线程
- python中线程进程
- Python进程和线程
- python进程、线程、协程
- Python的线程和进程
- THU2015 fall 2-2 Train
- 《C Primer Plus》学习笔记之 C数据的属性(一)数据类型
- iOS开发经验总结—内存管理
- SQL Server中Len和DataLength的区别
- 算法
- python进程&线程
- html5标签学习
- iOS9 怎么使用 Http 网络请求
- array_unique
- JFrame 的层次结构 及 背景设置说明
- 函数参数中带省略号的用法
- 统计list中重复项的个数
- 红尘牵绊,江湖儿女惹情长
- iOS夯实:内存管理