易截截图软件、单文件、免安装、纯绿色、仅160KB

[Python module] multiprocessing


multiprocessing — Process-based “threading” interface
Introduction
multiprocessing is a package that supports spawning processes using an API similar to the threading module. The multiprocessing package offers both local and remote concurrency, effectively side-stepping the Global Interpreter Lock by using subprocesses instead of threads. Due to this, the multiprocessing module allows the programmer to fully leverage multiple processors on a given machine. It runs on both Unix and Windows.
multiprocessing包利用threading模块相似的API来支持spawn进程。multiprocessing包有效的解决了GIL。
 
Warning
Some of this package’s functionality requires a functioning shared semaphore implementation on the host operating system. Without one, the multiprocessing.synchronize module will be disabled, and attempts to import it will result in an ImportError. See issue 3770 for additional information.
Note
Functionality within this package requires that the __main__ method be importable by the children. This is covered in Programming guidelines however it is worth pointing out here. This means that some examples, such as the multiprocessing.Pool examples will not work in the interactive interpreter. For example:
>>> from multiprocessing import Pool
>>> p = Pool(5)
>>> def f(x):
... return x*x
...
>>> p.map(f, [1,2,3])
Process PoolWorker-1:
Process PoolWorker-2:
Traceback (most recent call last):
AttributeError: 'module' object has no attribute 'f'
AttributeError: 'module' object has no attribute 'f'
AttributeError: 'module' object has no attribute 'f'
The Process class
In multiprocessing, processes are spawned by creating a Process object and then calling its start() method. Process follows the API of threading.Thread. A trivial example of a multiprocess program is
from multiprocessing import Process
def f(name):
print('hello', name)
if __name__ == '__main__':
p = Process(target=f,


相关文档:

pylibpcap: python module for libpcap

#!/usr/bin/env python2
import pcap
import sys
import string
import time
import socket
import struct
protocols={socket.IPPROTO_TCP:'tcp',
           socket.IPPROTO_UDP:'udp',
           socket ......

Python发展史

Python的创始人为Guido van
Rossum。1989年圣诞节期间,在阿姆斯特丹,Guido为了打发圣诞节的无趣,决心开发一个新的脚本解释程序,做为 ABC
语言的一种继承。之所以选中 Python(大蟒蛇的意思)作为程序的名字,是因为他是一个Monty Python的飞行马戏团的爱好者。
ABC是由Guido参加设计的一种教学语言。就Guido本人看 ......

python中MySQLdb的简单使用

对数据库的操作基本分为三步:
 
连接数据库
根据需要执行SQL语句,接受返回值
关闭连接
我们正常的数据库应该都离不开这三步,下来说说如何使用python中的MySQLdb模块进行这些操作:
首先,我们需要把MySQLdb引入到程序中
 
import MySQLdb
 
然后开始数据库操作
1.数据库连接
conn = MySQLdb. ......

python天天进步(2) 文件操作之遍历目录

 
Python的os模块,包含了普遍的操作系统功能,这里主要学习与路径相关的函数:
os.listdir(dirname):列出dirname下的目录和文件
os.getcwd():获得当前工作目录
os.curdir:返回当前目录('.')
os.chdir(dirname):改变工作目录到dirname
os.path.isdir(name):判断name是不是一个目录,name不是目录就返回false ......

[Python module] select

16.1. select — Waiting for I/O completion¶
This module provides access to the select and poll functions available in most operating systems, epoll available on Linux 2.5+ and kqueue available on most BSD. Note that on Windows, it only works for sockets; on other operating systems, it al ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号