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 also works for other file types (in particular, on Unix, it works on pipes). It cannot be used on regular files to determine whether a file has grown since it was last read.
The module defines the following:
这个模块提供大多数操作系统的select和poll功能。 epoll在Linux2.5+可用,kqueue则用于BSD。在winodws系统上,它仅用于socket,在其他系统下,它也可以用于其他类型(特别在 Unix 下,它还可以用于 管道)。它不能用来确定自从上次读取以后是否普通文件有所增长。
exception select. error ¶ The exception raised when an error occurs. The accompanying value is a pair containing the numeric error code from errno and the corresponding string, as would be printed by the C function perror .
在发生错误将引发 ......
8.8. queue — A synchronized queue class¶
queue -- 一个同步队列类
The queue module implements multi-producer, multi-consumer queues. It is especially useful in threaded programming when information must be exchanged safely between multiple threads. The Queue class in this module implements all the required locking semantics. It depends on the availability of thread support in Python; see the threading module.
queue模块处理多生产者和多消费者的队列。在多线程间信息的安全交换非常有用。这个module的Queue类处理所需的locking语义,它依赖于threading模块。
Implements three types of queue whose only difference is the order that the entries are retrieved. In a FIFO queue, the first tasks added are the first retrieved. In a LIFO queue, the most recently added entry is the first retrieved (operating like a stack). With a priority queue, the entries are kept sorted (using the heapq module) and the lowest valued entry is retrieved first.
三种类型的队列,FIFO,LIFO,以及优先队列(使用heap ......
threading — Higher-level threading interface
This module constructs higher-level threading interfaces on top of the lower level _thread module. See also the queue module.
The dummy_threading module is provided for situations where threading cannot be used because _thread is missing.
这个模块是构建在底层_thread模块上的。
dummy_threading模块提供了可threading(由于_thread缺失)模块不能使用的情况。
Note
While they are not listed below, the camelCase names used for some methods and functions in this module in the Python 2.x series are still supported by this module.
This module defines the following functions and objects:
threading.active_count() Return the number of Thread objects currently alive. The returned count is equal to the length of the list returned by enumerate().
threading.Condition() A factory function that returns a new condition variable object. A condition variable allows one or more threads to wait until they are notified by another thread.th ......
确实,数据库的维护常常交给那些专业的数据库管理员,但是作为一个开发者,你也许偶尔需要暂时从事这个工作。所以,试一试这两个SQL服务器维护技巧:轻松改变数据库拥有者、整理索引碎片。谁会想到你甚至可以给那些数据库管理员教上一两个新技巧呢?重指定数据库拥有者当回复或者新建数据库时,你有没有注意到SQL Server把数据库的拥有者置为你的NT登录名?仅仅为了确保不同数据库间的一致性(更别提安全性因素了),你也许考虑用系统过程sp_changedbowner来把数据库拥有者改为其它用户如系统管理员(SA)。你也许已经写了这样一段脚本用来扫描所有用户数据库并把数据库拥有者重指定为系统管理员。
系统过程sp_changedbowner有一个参数,即@map,其缺省值为空(null),该过程可以把数据库旧有的拥有者的别名重映射为新的数据库拥有者,如系统管理员。
为了演示该过程,让我们首先建立一个尽可能小的数据库模型,然后运行sp_helpuser指令来看看新创建的用户名清单:
CREATE DATABASE test GO USE test GO EXEC sp_helpuser GO
这些代码执行后,输出应该列出数据库拥有者的清单(db_owner)。如果你使用Windows NT认证身份 ......
一、Delphi中流的基本概念及函数声明
在Delphi中,所有流对象的基类为TStream类,其中定义了所有流的共同属性和方法。
TStream类中定义的属性介绍如下:
1、Size:此属性以字节返回流中数据大小。
2、Position:此属性控制流中存取指针的位置。
Tstream中定义的虚方法有四个:
1、Read:此方法实现将数据从流中读出。
函数原形为:Function Read(var Buffer;Count:Longint):Longint;virtual;abstract;
参数Buffer为数据读出时放置的缓冲区,Count为需要读出的数据的字节数,该方法返回值为实际读出的字节数,它可以小于或等于Count中指定的值。
2、Write:此方法实现将数据写入流中。
函数原形为:Function Write(var Buffer;Count:Longint):Longint;virtual;abstract;
参数Buffer为将要写入流中的数据的缓冲区,Count为数据的长度字节数,该方法返回值为实际写入流中的字节数。
3、Seek:此方法实现流中读取指针的移动。
函数原形为:Function Seek(Offset:Longint;Ori ......
//分割文件的函数
{参数 1 是要分割的文件名; 参数 2 是要风格文件的大小, 单位是 KB}
{分割后的文件名扩展名用序号替换}
function SplitFile(const FileName: string; Size: Cardinal): Boolean;
var
fStream: TFileStream; {原始文件}
toStream: TMemoryStream; {分文件}
p,i: Integer; {p 记录当前指针位置; i 记录这是第几个分的文件}
begin
Result := False;
Size := Size * 1024; {把大小的单位转换为字节}
fStream := TFileStream.Create(FileName, fmOpenRead);
p := 0;
i := 0;
toStream := TMemoryStream.Create;
while p < fStream.Size do
begin
toStream.Clear; {清空上次数据}
fStream.Position := p; {放好指针位置}
if fStream.Size-p < Size then Size := fStream.Size-p; {最后一个时, 有多少算多少}
toStream.Copyfrom(fStream, Size); {复制}
toStream.SaveToFile(FileName + '.' + IntToStr ......