python基于multiprocessing的多进程创建方法

yipeiwu_com5年前Python基础

本文实例讲述了python基于multiprocessing的多进程创建方法。分享给大家供大家参考。具体如下:

import multiprocessing
import time
def clock(interval):
  while True:
    print ("the time is %s"% time.time())
    time.sleep(interval)
if __name__=="__main__":
  p = multiprocessing.Process(target=clock,args=(15,))
  p.start() #启动进程

定义进程的另一种方法,继承Process类,并实现run方法:

import multiprocessing
import time
class ClockProcessing(multiprocessing.Process):
  def __init__(self, intverval):
    multiprocessing.Process.__init__(self)
    self.intverval = intverval
  def run(self):
    while True:
      print ("the time is %s"% time.time())
      time.sleep(self.interval)
if __name__=="__main__":
  p = ClockProcessing(15)
  p.start() #启动进程

希望本文所述对大家的Python程序设计有所帮助。

相关文章

妙用itchat! python实现久坐提醒功能

本文实例为大家分享了python久坐提醒的具体实现代码,供大家参考,具体内容如下 #!/usr/bin/envy python3 #-*- coding:utf-8 -*- impo...

python调用matplotlib模块绘制柱状图

我们可以调用matplotlib 绘制我们的柱状图,柱状图可以是水平的也可以是竖直的。 在这里我先记录下竖直的柱状图怎么绘制 在这里一般用到的函数就是bar # bar(left,...

Python函数和模块的使用总结

函数和模块的使用 在讲解本章节的内容之前,我们先来研究一道数学题,请说出下面的方程有多少组正整数解。 $$x_1 + x_2 + x_3 + x_4 = 8$$ 事实上,上面的问题等同...

Python模块future用法原理详解

这篇文章主要介绍了Python模块future用法原理详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 计算机的知识太多了,很多东西...

Pytorch抽取网络层的Feature Map(Vgg)实例

这边我是需要得到图片在Vgg的5个block里relu后的Feature Map (其余网络只需要替换就可以了) 索引可以这样获得 vgg = models.vgg19(pretra...