#! /usr/bin/env python
# -*- coding:utf-8 -*- """
python中的多线程其实并不是真正的多线程(全局解释器锁(GIL)存在)
多进程包multiprocessing:可以轻松完成从单进程到并发执行的转换
multiprocessing支持子进程、通信和共享数据、执行不同形式的同步,提供了Process、Queue、Pipe、Lock等组件
"""
import multiprocessing
import time
"""
创建进程的类:Process([group [, target [, name [, args [, kwargs]]]]]),
target表示调用对象,
args表示调用对象的位置参数元组。
kwargs表示调用对象的字典。
name为别名。
group实质上不使用。
方法:is_alive()
join([timeout])
run()
start() 启动某个进程
terminate() 属性:
authkey
daemon(要通过start()设置) 在子线程设置后父进程终止后自动终止,且自己不能产生新进程,必须在start()之前设置。
exitcode(进程在运行时为None、如果为–N,表示被信号N结束)、
name
pid
""" ## 将进程定义为类
class ClockProcess(multiprocessing.Process):
def __init__(self, interval):
multiprocessing.Process.__init__(self)
self.interval = interval def run(self):
n = 5
while n > 0:
print("the time is {0}".format(time.ctime()))
time.sleep(self.interval)
n -= 1 if __name__ == '__main__':
p = ClockProcess(3)
p.start()

  

最新文章

  1. 使用 Centos 7 的 systemctl 管理服务
  2. Swift 类构造器的使用
  3. 工作中遇到的UIScrollview的问题及解决方案
  4. syslog实例详解rsyslog
  5. Struts1 中实现Action跳转地址栏变化的方法
  6. System.Web.Http.Tracing 在webapi里面应用
  7. 《算法问题实战策略》-chaper14-整数论
  8. java围棋游戏源代码
  9. SAP 用户参数 ME_USE_GRID
  10. es上的的Watcher示例
  11. 第三周博客之二---Oracle中的sql语句
  12. SSAS 后端数据库访问模块中存在错误。 为绑定指定的大小太小,导致一个或多个列值被截断。
  13. TEST mathjax
  14. IntelliJ IDEA 2017版 spring-boot 2.03 去除控制台logo;去除springboot 图标;去除springboot 图
  15. CUDA C Programming Guide 在线教程学习笔记 Part 11
  16. SpookyOTP
  17. Framwork框架-网络客户端的使用
  18. jquery on方法(事件委托)
  19. Zabbix自动发现与主动注册
  20. spark 性能优化

热门文章

  1. HDU5015 233 Matrix —— 矩阵快速幂
  2. 牛逼的This使用
  3. ffmpeg xcode 中的使用
  4. jmeter中的响应断言
  5. android读取apk中已经存在的数据库信息
  6. Sublime Text 快捷键及使用技巧的学习整理
  7. hdu-4989 Summary(水题)
  8. kallsyms
  9. org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bireportSqlSessionFactory' defined in URL
  10. Asset Catalog Help (五)---Migrating an iOS App Icon Set or Launch Image Set