
python
xuejinliang
这个作者很懒,什么都没留下…
展开
-
Python查找字符串高亮显示
#!/usr/bin/env python#_*_ coding:utf-8 _*_user_file = 'userlist.txt'info = raw_input('Input the info to search: ')f = file(user_file,'rb')count = 0for line in f.xreadlines(): line =原创 2016-06-07 13:37:07 · 5980 阅读 · 0 评论 -
Python多进程生成多线程
python利用多进程生成多线程 #!/usr/bin/env python#_*_ coding:utf-8 _*_ from multiprocessing import Poolimport threadingimport osdef f(n): #每个进程生成4个线程 for i in range(4): t = th原创 2016-07-06 14:33:47 · 374 阅读 · 0 评论 -
Python生成进程方法2-Pool
Python生成进程方法#!/usr/bin/env python#_*_ coding:utf-8 _*_from multiprocessing import Pooldef f(n): return n*n if __name__ == '__main__': pool = Pool(processes=5) res_list = [原创 2016-07-06 14:00:08 · 334 阅读 · 0 评论 -
Python创建进程1-Process方法实现
Python生成进程利用Process模块来生成进程 #!/usr/bin/env python#_*_ coding:utf-8 _*_from multiprocessing import Processimport timedef f(x,n): print x print n time.sleep(2)if __name__原创 2016-07-06 11:40:46 · 5011 阅读 · 0 评论 -
Python实现进程资源共享
进程是CPU最小的资源分配的单位。进程之间的资源是不能共享的。但是线程之间的资源可以是共享的。下面简单的介绍两种方法实现进程之间资源的共享。1、queue方法:#!/usr/bin/env python#_*_ coding:utf-8 _*_from multiprocessing import Process,Queuedef f(q,x): q.put([x原创 2016-07-06 10:10:27 · 1869 阅读 · 0 评论 -
python多进程与多线程之间的联系
Python多进程和多线程简析进程是资源分配的最小单位,但是线程是CPU执行的最小的单元,进程和线程的选择,和程序是属于CPU密集型或者是IO密集型也是存在着很大的关系的。1、CPU密集型:如果属于CPU密集型,程序选择多线程。首先一个线程可以在多个CPU之间运行,如果分配多个CPU可以明显的提高程序的效率。2、IO密集型:IO操作本身就是不需要CPU进行处理的,并且单个线程只原创 2016-07-06 10:02:07 · 334 阅读 · 0 评论 -
python manager 实现线程资源共享
from multiprocessing import Process,Managerdef f(d,l): d[0] = 0 d['2'] = 'hello world' d['3'] = None l.reverse()if __name__ == '__main__': manger = Manager() #声明一个原创 2016-07-05 22:31:44 · 724 阅读 · 0 评论 -
ssh 免密码登陆
#!/usr/bin/env python#_*_ coding:utf-8 _*_import paramikossh_private_path = 'home/hello/.ssh/id_rsa'key = paramiko.RSAKey.from_private_key_file(ssh_private_path)ssh = paramiko.SSHCl原创 2016-06-29 18:20:24 · 405 阅读 · 0 评论 -
ssh登陆
#!/usr/bin/env python#_*_ coding:utf-8 _*_import paramikossh = paramiko.SSHClient()ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())ssh.connect('192.168.145.129',22,'root','exit'原创 2016-06-29 18:02:29 · 314 阅读 · 0 评论 -
python生产者与消费者问题
#!/usr/bin/env python#_*_ coding:utf-8 _*_from threading import Threadimport timefrom Queue import Queueclass producer(Thread): #producer __init__ def __init__(self,name,queue):原创 2016-06-29 16:24:47 · 502 阅读 · 0 评论 -
Python 查找list中的某个元素的所有的下标
#!/usr/bin/env python#_*_ coding:utf-8 _*_name = ['hello', 'world', 'a', 'b', 'c', 1, 2, 3, 'hello', 'world', 'a', 'b', 'c', 1, 2, 3]first_pos = 0for i in range(name.count(2)): new_list原创 2016-06-05 22:19:19 · 22481 阅读 · 0 评论 -
Python 用户登录练习
#!/usr/bin/env python#_*_ coding:utf-8 _*_import os import syscount=3retry_count=0account_file='/home/hello/login.txt'lock_file='/home/hello/lock.txt'while retry_count username=r原创 2016-06-05 22:18:27 · 858 阅读 · 0 评论 -
Python-2 循环输出
#!/usr/bin/env python#_*_ coding:utf-8 _*_count = 0 print_num=input('input the number you want to got: ')while count if count == print_num: print 'the number is got',count原创 2016-06-05 22:17:30 · 847 阅读 · 0 评论 -
python格式化输出
#!/usr/bin/env python#_*_ codeing:utf-8 _*_name=raw_input('name:')job=raw_input('job:')salary=raw_input('salary:')real_age=23for i in range(10): age=input('age:') if age > real_原创 2016-06-05 22:16:38 · 255 阅读 · 0 评论 -
Python pip安装模块报错
Python在安装模块的过程中,有时候会遇到如下问题:error: could not create'/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/greenlet':Operation not permitted简单的处理方法就是:pip install module_name –原创 2016-12-02 17:22:38 · 2622 阅读 · 0 评论