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

yipeiwu_com6年前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程序设计有所帮助。

相关文章

linux平台使用Python制作BT种子并获取BT种子信息的方法

本文实例讲述了linux平台使用Python制作BT种子并获取BT种子信息的方法。分享给大家供大家参考,具体如下: 最近研究了一下linux BT服务器环境的搭建,需要在linux下制作...

python pyinstaller 加载ui路径方法

如下所示: class Login(QMainWindow): """登录窗口""" global status_s global connect_signal de...

python正则中最短匹配实现代码

python正则中最短匹配实现代码

下面从一个例子入手: 利用正则表达式解析下面的XML/HTML标签: <composer>Wolfgang Amadeus Mozart</composer>...

python 将字符串转换成字典dict

复制代码 代码如下:JSON到字典转化:dictinfo = simplejson.loads(json_str) 输出dict类型 字典到JSON转化:jsoninfo = simpl...

python3使用tkinter实现ui界面简单实例

python3使用tkinter实现ui界面简单实例

复制代码 代码如下:import timeimport tkinter as tkclass Window:    def __init__(self,...