python实现进程的并发
__author__ = 'luozt'
import telnetlib
import multiprocessing
import random
def telnet(ip,hostname): tn = telnetlib.Telnet(ip)
print("begin telnet "+str(hostname)+"...")
tn.read_until("Username:".encode('ascii')) tn.write("nb".encode('ascii')+b"\n") tn.read_until(b"Password:")
tn.write("nb".encode('ascii') + b"\n") print(hostname.encode('ascii')) tn.read_until(hostname.encode('ascii')+ b">") tn.write("enable".encode('ascii') + b"\n") tn.read_until("Password:".encode('ascii'))
tn.write("nb".encode('ascii') + b"\n") tn.read_until(hostname.encode('ascii')+b'#') tn.write("terminal length 0".encode('ascii') + b"\n")
tn.read_until(hostname.encode('ascii')+b'#')
tn.write("show run".encode('ascii') + b"\n")
aa = tn.read_until(hostname.encode('ascii')+b'#')
#print(aa.decode('ascii')) aa1="C:\\tt\\"+hostname+".txt"
# with open("C:\\luo.txt",'a+') as ff:
with open(aa1,'a+') as ff:
ff.write(aa.decode('ascii'))
ff.write("exit%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
tn.write(b"exit\n")
#print("exit") def multitelnet(): try:
pool=multiprocessing.Pool(processes=4)
f=open("C:\\12345.txt","r")
num=1
multipro=[]
while True:
line=f.readline().strip('\n')
if line:
argu=line.split('\t')
#print (argu[0])
#print (argu[1])
print( '第'+str(num)+'个进程已启动')
num+=1
pool.apply_async(telnet,(argu[0],argu[1]))
# multipro.append(t)
# t.start()
# t.join()
# print( '第'+str(num)+'个进程已启动')
# num+=1
else:
break
f.close()
pool.close()
pool.join()
print ("Sub-process(es) done")
# for j in multipro:
# j.start()
# j.join()
# print( '第'+str(num)+'个进程已启动')
# num+=1
except Exception as e:
print (e) if __name__ == "__main__" :
multitelnet()
# telnet("172.25.11.2",b"mpls-vrf-PE1")
python实现进程的并发的更多相关文章
- python 使用多进程实现并发编程/使用queue进行进程间数据交换
import time import os import multiprocessing from multiprocessing import Queue, pool ""&qu ...
- {Python之进程} 背景知识 什么是进程 进程调度 并发与并行 同步\异步\阻塞\非阻塞 进程的创建与结束 multiprocess模块 进程池和mutiprocess.Poll
Python之进程 进程 本节目录 一 背景知识 二 什么是进程 三 进程调度 四 并发与并行 五 同步\异步\阻塞\非阻塞 六 进程的创建与结束 七 multiprocess模块 八 进程池和mut ...
- Python进阶----计算机基础知识(操作系统多道技术),进程概念, 并发概念,并行概念,多进程实现
Python进阶----计算机基础知识(操作系统多道技术),进程概念, 并发概念,并行概念,多进程实现 一丶进程基础知识 什么是程序: 程序就是一堆文件 什么是进程: 进程就是一个正在 ...
- Python 多线程教程:并发与并行
转载于: https://my.oschina.net/leejun2005/blog/398826 在批评Python的讨论中,常常说起Python多线程是多么的难用.还有人对 global int ...
- python进阶------进程线程(一)
Python中的进程线程 一.进程线程的概念 1.1进程: 进程就是一个程序在一个数据集上的一次动态执行过程.进程一般由程序.数据集.进程控制块三部分组成.我们编写的程序用来描述进程要完成哪些功能以及 ...
- Python之进程
进程 进程(Process)是计算机中的程序关于某数据集合上的一次运行活动,是系统进行资源分配和调度的基本单位,是操作系统结构的基础.在早期面向进程设计的计算机结构中,进程是程序的基本执行实体:在当代 ...
- Python之进程 3 - 进程池和multiprocess.Poll
一.为什么要有进程池? 在程序实际处理问题过程中,忙时会有成千上万的任务需要被执行,闲时可能只有零星任务.那么在成千上万个任务需要被执行的时候,我们就需要去创建成千上万个进程么?首先,创建进程需要消耗 ...
- Python之进程 1 - 基本概念
一 背景知识 顾名思义,进程即正在执行的一个过程.进程是对正在运行程序的一个抽象. 进程的概念起源于操作系统,是操作系统最核心的概念,也是操作系统提供的最古老也是最重要的抽象概念之一.操作系统的其他所 ...
- python之进程池与线程池
一.进程池与线程池介绍 池子使用来限制并发的任务数目,限制我们的计算机在一个自己可承受的范围内去并发地执行任务 当并发的任务数远远超过了计算机的承受能力时,即无法一次性开启过多的进程数或线程数时就应该 ...
随机推荐
- UI控件之UIPickerView的协议方法
UIPickerView:选择视图,父类是UIView UIPickerView *pickerView=[[UIPickerView alloc]initWithFrame:CGRectMake(1 ...
- 财经世界(2)A股B股和H股
在发行过程中,公司通过章程给不同股份形式赋予不同的权益,使公司股份出现A股.B股等形式.我国上市公司的股票有A股.B股.H股.N股.S股等的区分.这一区分的主要依据股票的上市地点和所面对的投资者而定. ...
- 常用的机器学习&数据挖掘知识点
Basis(基础):MSE(Mean Square Error 均方误差),LMS(LeastMean Square 最小均方),LSM(Least Square Methods 最小二乘法),MLE ...
- 【leetcode刷题笔记】Minimum Window Substring
Given a string S and a string T, find the minimum window in S which will contain all the characters ...
- C语言:内存字节对齐详解
转:http://blog.csdn.net/arethe/article/details/2548867 一.什么是对齐,以及为什么要对齐: 1. 现代计算机中内存空间都是按照byte划分的,从理论 ...
- 封装一个既能遍历数组又能遍历对象的的forEach函数
function newforEach(obj,fn) { var key; if(obj instanceof Array){ obj.forEach(function(item,index){ f ...
- gitblit搭建git服务器
如果你的公司使用git作为版本管理工具,那么对gitblit应该也不会陌生.gitblit是一个开源的git服务器java实现,一般情况下gitblit都是由别人已经搭建好你直接使用就行了,除非你就是 ...
- lockingModel in log4net 日志文件不能被其他进程写入
http://logging.apache.org/log4net/release/faq.html#single-file How do I get multiple process to log ...
- EXTJS4.2 级联 下拉
items: [ { xtype: "fieldcontainer", layout: "hbox", items: [{ xtype: 'combo', na ...
- StringToInt(atoi) 字符串转换成整数
public class StringToInt { public int atoi(String s) { long num = 0; int minus = 0; if(s==null) { re ...