??xml version="1.0" encoding="utf-8" standalone="yes"?>
随着搜烦的垂直分? 搜烦市场也被l化
1. 视频搜烦的突? youtube ?007.10 ?2008.10 的搜索增长了114%, 占了google 搜烦?6%.
2. 实时消息的发? ?a >twitter Z? 市场对突发事件的要求的强? 使得twitter q速发? twitter 的搜?http://search.twitter.com/)与传l引擎依赖内容相关以及链接关pȝ? 更注重时间的相关?
Gerry campbell 的文?nbsp;Search is broken – really broken. 的一个图说明了这U趋?
]]>
BHO兌原理 (BHO兌的是SHDOCVW,也就是说不只兌IE,下面全部用IE来说?
1.IE的窗口打开?先寻找HKLM下的SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Browser Helper Objects\ 里的CLSID,q些CLSID,都对应着相应的BHO插gQ然后根据这个CLSID到HKCR下的CLSIDs里找到此插g的信息,包括文g位置{?br>2.IEҎ扑ֈ的CLSID信息创徏 BHO 对象,q且查找 IObjectWithSite 接口. (q个接口非常?只有SetSite和GetSite两个Ҏ)
3.IE把IWebBrowser2(览器插?传到 BHO ?SetSite ҎQ用户在此方法中可挂载自q事g处理Ҏ?br>4.H口关闭?IE?null 传到 BHO ?SetSite ҎQ此Ҏ用来L挂蝲的事件处理方法?/p>
~写BHO程
1.创徏IObjectWithSite昑ּ接口Q创?COM cdQ实现承IObjectWithSite接口
2.实现此接口ƈ在SetSiteҎ里加上所要挂载的事g
3.处理事g
4.注册此BHO到注册表中HKLM下的Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Browser Helper Objects;(HKCR下的CLSIDs是根据上面的路径自动注册?
5?net 下须讄此BHO目?配置属性_>生成 中ؓInterop注册为TrueQ这h能将.net cd文g注册到COM
删除BHO
打开注册表项?HKLM下的Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Browser Helper Objects 可以看到下面有一些CLSID?q些值对应相关的插g,点击可以在默认值后看到相关插g的名U?可以复制相关CLSID到注册表中搜索相关CLSID,扑ֈ后打开InprocServer32可以看到相关文g的\?至于DLL文g{可以用UEDIT32.exe工具打开查看具体信息,当然也可以用修改E序cȝeXeScope.exe研究一?
h据具体情况删除相关键值和相关文g!
REF:
BHO 的编?nbsp;
VCKBase 关于IE ~程文档中心
C++中用BHO来屏蔽特定网?/a>
览器集成教?自定义浏览器
1. Define early on what success means for you, the team and the business
You have to have a clear idea of what you want. You also have to understand what team members and the management want. You also have to be aware that what people really want, what they say the want and sometimes even what they think they want are very different things. Try to be very honest at least with yourself. Success has different definitions for different people. If there is a big disconnect between these definitions you have a problem before you start.
2. Believe in the project: idea, architecture, time, team
You cannot have any kind of success if you are convinced you lead a team of morons to implement a stupid idea using the wrong architecture in a ridiculously short time. You have to really believe in the project to have a chance to success. This does not mean lie to yourself. It means do whatever you can to understand your concerns and work on them with the management. As for the architecture, it is best if you have a heavy word or if you are the architect.
3. Understand the domain, the business requirements and the technical challenges
You should be an expert in the technologies used for implementation. You also have to become very knowledgeable in the problem domain and the business case. This will help you understand the business decisions dropped on your head from upstairs and also will help you stand a chance at negotiating them.
4. Know your team: strengths, weaknesses, ambitions and personalities
Software is created by people. Your job as a “tech lead” is to support them in doing that, both from a technical point of view and at a human level. You want to lead a team of motivated and enthusiastic people. But each person gets motivated by different things.
5. Have a plan as a result of a planning activity
“Plans are useless but planning is essential” - (Dwight D Eisenhower, US President, general 1890-1969). Planning will make you think about the problems you face in detail. Also keep in mind that “a plan is just a list of things that ain’t gonna happen” - (Benicio Del Torro in “The Way of the Gun”).
6. Be part in the design of everything
This does not mean do the whole design. You want to empower team members. But your job is to understand and influence each significant subsystem in order to maintain architectural integrity.
7. Get your hands dirty and code
Yes you should take parts of the code and implement them. Even the least glamorous parts. This will help you not getting stuck alone between management and the team. It will also help you gain respect in the team.
8. Act as a communication proxy for your team
In long complex projects with big teams communication is one of the most complicated aspects. The more people you have involved in solving a problem the bigger the communication matrix becomes. Since people need information to be able to make the right decisions this will lead to an exponential increase in the time consumed for communication. Agile methodologies alleviate this problem. But in the end it is up to you to propagate important information to the right people.
9. Make sure everybody understands the big picture: their work has implications
This will help you greatly because will allow team members to design and implement in a way that you don’t have to fight. It is also hard work from your part.
10. Fight for architecture and design consistency
Doing the right thing from the design and architecture point of view is not more costly. It is actually cheaper in every project longer than a couple of months. Every early investment in architecture pays for itself later during integration and maintenance. Even if you have to admit an occasional hack or prototype in the code base you should contain it in very specific modules.
11. Know the status of everybody’s work and detect slippage
This allows for corrective actions and for early communication with the management. You don’t want to be caught by surprise. Remember that during 90% of the allocated time for a task the code is 90% complete.
12. Record technical debt if you need shortcuts but try to maintain architectural integrity; report the debt
This one is very important for products that will have multiple releases. Technical debt should be analyzed at the beginning of each iteration.
13. Use the process that makes sense in your particular case
Tough one. Sometimes (most of the times?) the process is not up to you. In the enterprise usually the process is pre-decided. But always keep in mind that the process in itself means nothing. It is the people who give meaning to the process. Good people can make the worst process work while the wrong team cannot make any process work. Waterfall can be implemented in a very agile way and the agile methodologies can be applied with “rigor mortis” agility (see The Agile 800 Pounds Gorilla).
14. Avoid dogmas - question why everything is done the way is done; make sure everybody else knows the reasons
Sometimes I hear from programmers: we are agile and combine XP and Scrum and we also do TDD (Test Driven Development - I still hope for a TDD that means Thought Driven Development). The questions that pop up in my mind are: Do you need all those? Do you “really” do them by the book?
Anyway the point here is don’t do anything just because it is the way it has always been done. Understand why. Then explain the reasons to all team members. Rinse and repeat.
15. Avoid design by committee; listen to everybody but make your own decisions
No good design is born from referendum. There are lots of people making wild exotic suggestions when their a$$ is not on the line. There are also excessively prudent ideas born from fear. Even with good ideas you have to filter them and make them yours before you can include them in the design. A good architecture and a good design is usually born in one mind, an open mind that looks around. The obvious example is Linux.
该文ȝ?php 的一些模? 我用过的有smarty, template lib, q有后来用的 Savant. 感觉smarty 太复杂了, template lib 需要学习一些标{? q且不是很强? l合考虑q是Savant 最? 既可以用模板机? 另外面模板直接使用php 函数来输? 功能也还可以.
Smarty
Smarty is a template engine that compiles the templates into PHP scripts, then executes those scripts. Very fast, very flexible.
Savant
A powerful but lightweight PEAR-compliant template system. It is non-compiling, and uses PHP itself as its template language.
Heyes Template Class
A very easy to use, yet powerful and quick template engine that enables you to separate your page layout and design from your code.
FastTemplate
A simple variable interpolation template class that parses your templates for variables and spits out HTML with their values
ShellPage
A simple and easy to use class that lets you make whole websites based on template files for layouts. Change the template and your whole site changes.
STP Simple Template Parser
A simple, light weight and easy to use template parser class. It can assemble a page from several templates, output result pages to the browser or write them to the filesystem.
OO Template Class
An object oriented template class you can use in your own programs.
SimpleTemplate
A template engine to create and structure websites and applications. It can translate and compile the templates.
bTemplate
A small and fast template class that allows you to separate your PHP logic from your HTML presentation code.
ETS - easy template system
A template system that allows you to reshuffle templates with exactly the same data.
EasyTemplatePHP
A simple, yet powerful templating system for your site.
vlibTemplate
A fast, full featured template system that includes a caching and debugging class.
AvanTemplate
A template engine that is multi-byte safe and consumes little computing resource. It supports variable replacement and content blocks that can be set to hidden or shown.
Grafx Software’s Fast Template
A modification of the popular Fast Template system, this includes a cache function, debug console, and silent removal of unassigned dynamic blocks.
TemplatePower
A fast, simple and powerful template class. Features nested dynamic block support, block/file include support and show/hide unassigned variables.
TagTemplate
This library function was designed for use with template files and allows you to retrieve info from HTML files.
htmltmpl: templating engine
A templating engine for Python and PHP. Targeted to web application developers, who want to separate program code and design of their projects.
PHP Class for Parsing Dreamweaver templates
A simple class to parse a Dreamweaver template for use in custom mods for a Gallery 2 and a WordPress blog.
MiniTemplator (Template Engine)
A compact template engine for HTML files. It features a simple syntax for template variables and blocks. Blocks can be nested.
Layout Solution
Simplifies website development and maintenance. It holds commonly used variables and page elements so you don’t need to duplicate common layouts over and over.
Cached Fast Template
This inclusion into FastTemplate allows for caching of the template files, and can even cache with different specifications on separate blocks of content.
TinyButStrong
A template engine that supports MySQL, Odbc, Sql-Server and ADODB. It includes seven methods and two properties.
Brian Lozier’s php based template engine
Only 2k in size, very fast and object-orientated.
WACT
a template engine that separates code from design.
PHPTAL
a XML/XHTML template library for PHP.
ref:
http://www.sitepoint.com/forums/showthread.php?t=123769 对其他的php 模板q行了讨?/p>
另外值得说明的是, HTTP h是无状态的Q表明在处理一个请求时QWeb服务器ƈ不记住来自同一客户端的h?/p>
= Http h?
包含4个部? h行、请求头、空行和h数据
1. h?br>׃个标记组成:hҎ、请求URI和HTTP版本Q它们用I格分隔, 如:GET /index.html HTTP/1.1
HTTP 规范定义?U请求方法:
GET 索URI中标识资源的一个简单请?br>HEAD 与GETҎ相同Q服务器只返回状态行和头标,q不q回h文
POST 服务器接受被写入客户端输出流中的数据的请?br>PUT 服务器保存请求数据作为指定URI新内容的h
DELETE 服务器删除URI中命名的资源的请?br>OPTIONS 关于服务器支持的hҎ信息的请?br>TRACE Web服务器反馈Httph和其头标的请?br>CONNECT 已文档化但当前未实现的一个方法,预留做隧道处?/p>
2. h?[ 可无 ]
由关键字及值对l成Q每行一对,关键字和值用冒号Q?Q分隔。如
> User-Agent: curl/7.16.4 (i586-pc-mingw32msvc) libcurl/7.16.4 OpenSSL/0.9.7e zlib/1.2.2
> Host: www.baidu.com
> Accept: */*
具体h头如后所?
3. I
最后一个请求头之后是一个空行,发送回车符和退行,通知服务器以下不再有头标?/p>
4. h数据 [ 可无 ]
使用POST传送数据,最怋用的是Content-Type和Content-Length头标
= Web 响应
由四个部分组? 状态行、响应头、空行、响应数? ?
< HTTP/1.1 200 OK
< Date: Thu, 25 Sep 2008 05:14:30 GMT
< Server: BWS/1.0
< Content-Length: 3342
< Content-Type: text/html
< Cache-Control: private
< Expires: Thu, 25 Sep 2008 05:14:30 GMT
< Set-Cookie: BAIDUID=3A8165EF68FFEE5F605D33ADEF300BA1:FG=1; expires=Thu, 25-Sep-38 05:14:30 GMT; path=/; domain=.baidu.com
< P3P: CP=" OTI DSP COR IVA OUR IND COM "
<
<html><head><meta http-equiv=Content-Type content="text/html;charset=gb2312"><title>......
1.状态行
׃个标记组成:HTTP版本、响应代码和响应描述
HTTP版本:: 向客L指明其可理解的最高版本?br>响应代码:: 3位的数字代码Q指求的成功或失败,如果p|则指出原因?br>响应描述:: 为响应代码的可读性解释?br>?
< HTTP/1.1 200 OK
HTTP响应码划分如?见?Q?br>1xxQ信息,h收到Ql处?br>2xxQ成功,行ؓ被成功地接受、理解和采纳
3xxQ重定向Qؓ了完成请求,必须q一步执行的动作
4xxQ客L错误
2.响应?br>跟请求头一P它们指出服务器的功能Q标识出响应数据的细节?/p>
3.I
最后一个响应头标之后是一个空行,发送回车符和退行,表明服务器以下不再有头标?/p>
4.响应数据
HTML文和图像等Q就是HTML本n?
= HTTP?br>用以描述客户端或者服务器的属性、被传输的资源等, 分ؓ
1.通用头标Q即可用于请求,也可用于响应Q是作ؓ一个整体而不是特定资源与事务相关联?br>2.h头标Q允许客L传递关于自w的信息和希望的响应形式?br>3.响应头标Q服务器和于传递自w信息的响应?br>4.实体头标Q定义被传送资源的信息。即可用于请求,也可用于响应?/p>
下表描述在HTTP/1.1中用到的头标
Accept 定义客户端可以处理的媒体cdQ按优先U排序;
在一个以逗号为分隔的列表中,可以定义多种cd和用通配W。例如:Accept: image/jpeg,image/png,*/*
Accept-Charset 定义客户端可以处理的字符集,按优先排序Q?br> 在一个以逗号为分隔的列表中,可以定义多种cd和用通配W。例如:Accept-Charset: iso-8859-1,*,utf-8
Accept-Encoding 定义客户端可以理解的~码机制。例如:Accept-Encoding:gzip,compress
Accept-Language 定义客户端乐于接受的自然语言列表。例如:Accept-Language: en,de
Accept-Ranges 一个响应头标,它允许服务器指明Q将在给定的偏移和长度处Qؓ资源l成部分的接受请求?br> 该头标的D理解求范围的度量单位。例如Accept-Ranges: bytes或Accept-Ranges: none
Age 允许服务器规定自服务器生成该响应以来所l过的时间长度,以秒为单位?br> 该头标主要用于缓存响应。例如:Age: 30
Allow 一个响应头标,它定义一个由位于hURI中的ơ源所支持的HTTPҎ列表。例如:Allow: GET,PUT
AUTHORIZATION 一个响应头标,用于定义讉K一U资源所必需的授权(域和被编码的用户ID与口令)?br> 例如QAuthorization: Basic YXV0aG9yOnBoaWw=
Cache-Control 一个用于定义缓存指令的通用头标。例如:Cache-Control: max-age=30
Connection 一个用于表明是否保存socketq接为开攄通用头标。例如:Connection: close或Connection: keep-alive
Content-Base 一U定义基本URI的实体头标,Z在实体范围内解析相对URLs?br> 如果没有定义Content-Base头标解析相对URLsQ用Content-Location URIQ存在且l对Q或使用URIh?br> 例如QContent-Base: Http://www.myweb.com
Content-Encoding 一U介质类型修饰符Q标明一个实体是如何~码的。例如:Content-Encoding: zip
Content-Language 用于指定在输入流中数据的自然语言cd。例如:Content-Language: en
Content-Length 指定包含于请求或响应中数据的字节长度。例如:Content-Length:382
Content-Location 指定包含于请求或响应中的资源定位QURIQ?br> 如果是一l。对URL它也作ؓ被解析实体的相对URL的出发点?br> 例如QContent-Location: http://www.myweb.com/news
Content-MD5 实体的一UMD5摘要Q用作校验和?br> 发送方和接受方都计MD5摘要Q接受方其计算的g此头标中传递的D行比较?br> 例如QContent-MD5: <base64 of 128 MD5 digest>
Content-Range 随部分实体一同发送;标明被插入字节的低位与高位字节偏U,也标明此实体的总长度?br> 例如QContent-Range: 1001-2000/5000
Contern-Type 标明发送或者接收的实体的MIMEcd。例如:Content-Type: text/html
Date 发送HTTP消息的日期。例如:Date: Mon,10PR 18:42:51 GMT
ETag 一U实体头标,它向被发送的资源分派一个唯一的标识符?br> 对于可以使用多种URLh的资源,ETag可以用于定实际被发送的资源是否为同一资源?br> 例如QETag: "208f-419e-30f8dc99"
Expires 指定实体的有效期。例如:Expires: Mon,05 Dec 2008 12:00:00 GMT
Form 一U请求头标,l定控制用户代理的h工用L电子邮g地址。例如:From: webmaster@myweb.com
Host 被请求资源的L名。对于用HTTP/1.1的请求而言Q此域是强制性的。例如:Host: www.myweb.com
If-Modified-Since 如果包含了GEThQ导致该h条g性地依赖于资源上ơ修Ҏ期?br> 如果出现了此头标Qƈ且自指定日期以来Q此资源已被修改Q应该反回一?04响应代码?br> 例如QIf-Modified-Since: Mon,10PR 18:42:51 GMT
If-Match 如果包含于一个请求,指定一个或者多个实体标记。只发送其ETag与列表中标记区配的资源?br> 例如QIf-Match: "208f-419e-308dc99"
If-None-Match 如果包含一个请求,指定一个或者多个实体标记。资源的ETag不与列表中的M一个条件匹配,操作才执行?br> 例如QIf-None-Match: "208f-419e-308dc99"
If-Range 指定资源的一个实体标讎ͼ客户端已l拥有此资源的一个拷贝。必MRange头标一同用?br> 如果此实体自上次被客L索以来,q不曾修改过Q那么服务器只发送指定的范围Q否则它发送整个资源?br> 例如QRange: byte=0-499<CRLF>If-Range:"208f-419e-30f8dc99"
If-Unmodified-Since 只有自指定的日期以来Q被h的实体还不曾被修改过Q才会返回此实体?br> 例如QIf-Unmodified-Since:Mon,10PR 18:42:51 GMT
Last-Modified 指定被请求资源上ơ被修改的日期和旉。例如:Last-Modified: Mon,10PR 18:42:51 GMT
Location 对于一个已l移动的资源Q用于重定向h者至另一个位|?br> 与状态编?02Q暂时移动)或?01Q永久性移动)配合使用?br> 例如QLocation: http://www2.myweb.com/index.jsp
Max-Forwards 一个用于TRACEҎ的请求头标,以指定代理或|关的最大数目,该请求通过|关才得以\由?br> 在通过h传递之前,代理或网兛_该减此数目。例如:Max-Forwards: 3
Pragma 一个通用头标Q它发送实现相关的信息。例如:Pragma: no-cache
Proxy-Authenticate cM于WWW-AuthenticateQ便是有意请求只来自h链(代理Q的下一个服务器的认证?br> 例如QProxy-Authenticate: Basic realm-admin
Proxy-Proxy-Authorization cM于授权,但ƈ非有意传递Q何比在即时服务器链中更进一步的内容?br> 例如QProxy-Proxy-Authorization: Basic YXV0aG9yOnBoaWw=
Public 列表昄服务器所支持的方法集。例如:Public: OPTIONS,MGET,MHEAD,GET,HEAD
Range 指定一U度量单位和一个部分被h资源的偏U范围。例如:Range: bytes=206-5513
Refener 一U请求头标域Q标明生请求的初始资源。对于HTML表单Q它包含此表单的Web面的地址?br> 例如QRefener: http://www.myweb.com/news/search.html
Retry-After 一U响应头标域Q由服务器与状态编?03Q无法提供服务)配合发送,以标明再ơ请求之前应该等待多长时间?br> 此时间即可以是一U日期,也可以是一U秒单位。例如:Retry-After: 18
Server 一U标明Web服务器Y件及其版本号的头标。例如:Server: Apache/2.0.46(Win32)
Transfer-Encoding 一U通用头标Q标明对应被接受方反向的消息体实施变换的cd。例如:Transfer-Encoding: chunked
Upgrade 允许服务器指定一U新的协议或者新的协议版本,与响应编?01Q切换协议)配合使用?br> 例如QUpgrade: HTTP/2.0
User-Agent 定义用于产生h的Y件类型(典型的如Web览器)?br> 例如QUser-Agent: Mozilla/4.0(compatible; MSIE 5.5; Windows NT; DigExt)
Vary 一个响应头标,用于表示使用服务器驱动的协商从可用的响应表示中选择响应实体。例如:Vary: *
Via 一个包含所有中间主机和协议的通用头标Q用于满求。例如:Via: 1.0 fred.com, 1.1 wilma.com
Warning 用于提供关于响应状态补充信息的响应头标。例如:Warning: 99 www.myweb.com Piano needs tuning
www-Authenticate 一个提C用户代理提供用户名和口令的响应头标Q与状态编?01Q未授权Q配合用。响应一个授权头标?br> 例如Qwww-Authenticate: Basic realm=zxm.mgmt
= HTTP码应?br>响应码由三位十进制数字组成,它们出现在由HTTP服务器发送的响应的第一? 分五U类型,由它们的W一位数字表C:
- 1xxQ信息,h收到Ql处?br>- 2xxQ成功,行ؓ被成功地接受、理解和采纳
- 3xxQ重定向Qؓ了完成请求,必须q一步执行的动作
- 4xxQ客L错误Q请求包含语法错误或者请求无法实?br>- 5xxQ服务器错误Q服务器不能实现一U明显无效的h
下表昄每个响应码及其含义:
100 l箋
101 分组交换?br>200 OK
201 被创?br>202 被采U?br>203 非授权信?br>204 无内?br>205 重置内容
206 部分内容
300 多选项
301 怹C?br>302 扑ֈ
303 参见其他
304 未改?br>305 使用代理
307 暂时重定?br>400 错误h
401 未授?br>402 要求付费
403 止
404 未找?br>405 不允许的Ҏ
406 不被采纳
407 要求代理授权
408 h时
409 冲突
410 q期?br>411 要求的长?br>412 前提不成?br>413 h实例太大
414 hURI太大
415 不支持的媒体cd
416 无法满的请求范?br>417 p|的预?br>500 内部服务器错?br>501 未被使用
502 |关错误
503 不可用的服务
504 |关时
505 HTTP版本未被支持
= 实例
== POST 数据
== 上传一个文?
假设接受文g的网늨序位?a
bb
ccc
客户端链?192.168.29.65 ? 应该发送如下http hQ?br>POST /upload_file/UploadFile HTTP/1.1
Accept: text/plain, */*
Accept-Language: zh-cn
Host: 192.168.29.65
Content-Type:multipart/form-data;boundary=---------------------------7d33a816d302b6
User-Agent: Mozilla/4.0 (compatible; OpenOffice.org)
Content-Length: 333
Connection: Keep-Alive
-----------------------------7d33a816d302b6
Content-Disposition: form-data; name="userfile1"; filename="E:s"
Content-Type: application/octet-stream
a
bb
ccc
-----------------------------7d33a816d302b6
Content-Disposition: form-data; name="text1"
foo
-----------------------------7d33a816d302b6
Content-Disposition: form-data; name="password1"
bar
-----------------------------7d33a816d302b6--
(上面有一个回?
此内容必M字不差,包括最后的回R?
注意QContent-Length: 333 q里?33是红色内容的总长度(包括最后的回RQ?
注意q一行:
Content-Type: multipart/form-data; boundary=---------------------------7d33a816d302b6
Ҏ rfc1867, multipart/form-data是必ȝ.
---------------------------7d33a816d302b6 是分隔符Q分隔多个文件、表单项。其?3a816d302b6 是即时生成的一个数字,用以保整个分隔W不会在文g或表单项的内容中出现?strong>Form每个部分用分隔符分割Q分隔符之前必须加上"--"着两个字符(?-{boundary})才能被http协议认ؓ是Form的分隔符Q表C结束的话用在正的分隔W后面添?--"表示l束?/strong>
前面?---------------------------7d ?IE Ҏ的标?Mozila ?--------------------------71.
每个分隔的数据的都可以用Content-Type来表CZ面数据的cdQ可以参考rfc1341 (http://www.ietf.org/rfc/rfc1341.txt) 例如Q?
Contect-Type:application/octet-stream 表示下面的数据是二进制数?
Contect-Type:text/plain 表示下面的数据是ASSCII码数?
Contect-Type:text/richtext 表示下面的数据是RTF格式
在运行时可能会生类?'import site' failed; use -v for traceback 的错? 原因是python 在import module 的时候的路径问题. ?U方法可以解?以前通过讄环境变量 PYTHONPATH 好像?.5 已经无效?.
0. 取消注释 Py_NoSiteFlag = 1;
q个只是取消import site , 当然如果在代码中要import 啥的? q是会出现错误的.
a. 讄环境变量 PYTHONHOME = D:\usr\Python
b. 在调?Py_Initialize 之前调用函数
Py_SetPythonHome("D:\\usr\\Python"); // 参数是python 的安装目?
2. 其他一些有用的资源
Python/C API Reference Manual (API 参? , Extending and Embedding the Python Interpreter (扩展及嵌入Python解释? 主要说明了如何扩展Python, lPython 写扩? 其中 5. Embedding Python in Another Application 一章讲qC在C++中嵌?调用Python 代码 )
使用C/C++扩展Python Ҏ Extending and Embedding the Python Interpreter 作了_, 很不错的一文? 但是跌了一些基 .
Building Hybrid Systems with Boost.Python 介绍了用boost.python 方便python 插g开? pythonl定c++E序 是其中文版本.
Embedding Python in Multi-Threaded C/C++ Applications 讲了c++在多U程环境如何使用Python , ?nbsp;C++多线E中调用python api函数 提供了一个多U程的封?
SCXX - A Simple Python/C++ API
http://davidf.sjsoft.com/mirrors/mcmillan-inc/scxx.html
C++扩展和嵌入Python应用 (介绍了一些Python/C API 函数, 以及ext 例子, 一般般)
http://hi.baidu.com/yunsweet/blog/item/20b08aeebaa2b1282cf534c7.html
3. Python 多线E的使用
zz http://blog.csdn.net/liguangyi/archive/2007/06/20/1659697.aspx
今天看了q一天关于多U程的应用中Q如何安全调用python斚w的资料,开始的时候看的简直头大如斗,被python语言的全局?Global Interpreter Lock)、线E状?Thread State ){都有点l晕了,后来l过各方面文章和帮助文档的相互参考,发现对于2.4/2.5版本Q提供了PyGILState_Ensure, PyGILState_ReleaseQ哎Q这下可方便大发了?/p>
一、首先定义一个封装类Q主要是保证PyGILState_Ensure, PyGILState_Release配对使用Q而且q个cL可以嵌套使用的?/p>
#include <python.h>
class PyThreadStateLock
{
public:
PyThreadStateLock(void)
{
state = PyGILState_Ensure( );
}
~PyThreadStateLock(void)
{
PyGILState_Release( state );
}
private:
PyGILState_STATE state;
};
二、在ȝE中Q这样处?/p>
// 初始?br> Py_Initialize();
// 初始化线E支?br> PyEval_InitThreads();
// 启动子线E前执行Qؓ了释放PyEval_InitThreads获得的全局锁,否则子线E可能无法获取到全局锁?br> PyEval_ReleaseThread(PyThreadState_Get());
// 其他的处理,如启动子U程{?br> ......
// 保证子线E调用都l束?br> PyGILState_Ensure();
Py_Finalize();
// 之后不能再调用Q何python的API
三、在ȝE,或者子U程中,调用python本n函数的都采用如下处理
{
class PyThreadStateLock PyThreadLock;
// 调用python的API函数处理
......
}
呵呵Q看q样是否非常单了?/p>
另外q有两个和全局锁有关的宏,Py_BEGIN_ALLOW_THREADS ?Py_END_ALLOW_THREADS。这两个宏是Z在较长时间的C函数调用前,临时释放全局锁,完成后重新获取全局锁,以避免阻塞其他python的线El运行。这两个宏可以这栯?/p>
{
class PyThreadStateLock PyThreadLock;
// 调用python的API函数处理
......
Py_BEGIN_ALLOW_THREADS
// 调用需要长旉的C函数
......
Py_END_ALLOW_THREADS
// 调用python的API函数处理
......
}
4. 可能的错误及解决
a. 在vs 200x ?debug 模式出现链接问题
extmodule.obj : error LNK2019: unresolved external symbol __imp___Py_Dealloc referenced in function _PySwigObject_format
extmodule.obj : error LNK2019: unresolved external symbol __imp___Py_NegativeRefcount referenced in function _PySwigObject_format
extmodule.obj : error LNK2001: unresolved external symbol __imp___Py_RefTotal
extmodule.obj : error LNK2019: unresolved external symbol __imp___PyObject_DebugFree referenced in function _PySwigObject_dealloc
extmodule.obj : error LNK2019: unresolved external symbol __imp___PyObject_DebugMalloc referenced in function _PySwigObject_New
extmodule.obj : error LNK2019: unresolved external symbol __imp__Py_InitModule4TraceRefs referenced in function _init_extmodule
主要是因?Py_DEBUG/Py_TRACE_REFS 引v, 修改 Python\include 下的 pyconfig.h, object.h 两个文gp?... 详见 http://www.nabble.com/link-error-in-debug-mode-td3126668.html
Command-Line Option |
Description |
---|---|
|
The default is to register the COM objects. |
|
Unregisters the objects. This removes all references to the objects from the Windows registry. |
|
Registers the COM servers in debug mode. We discuss debugging COM servers later in this chapter. |
|
Register (or unregister) the object quietly (i.e., don't report success). |