开源之路

忆往昔, 项羽不过江. 江东好风光! 今振臂一呼,率甲三千, 试问天!
posts - 86, comments - 55, trackbacks - 0, articles - 0
  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

2009年3月15日

UDP协议相比TCP要简单许多,虽然数据无法保证完整性.
先看一下client端的演示代码:

import socket
s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
port = 8000
host = '192.168.1.102'
while True:
  ...

收藏到:Del.icio.us





文章来源:http://riverbird.blogbus.com/logs/36597361.html

posted @ 2009-03-15 19:26 江边之鸟 阅读(1476) | 评论 (0)编辑 收藏

2009年3月3日

现在网络上的博客搬家服务,博客搬家工具越来越多,博客联盟大概收集了下,希望对那些想搬家的博客有所帮助。

一、和讯博客的“搬家公司”提供博客搬家服务 搬家服务地址:点这里

目标对象:新浪博客、搜狐博客、网易部落、TOM博客、MSN Space、天涯社区、中国博客网、中华部落阁、博客中国、博客中国专栏、DoNews、歪酷博客、敏思博客、BlogBUS、BlogDrive、百度空间、mop博客。

服务特色:该ID下博客文章、链...

收藏到:Del.icio.us





文章来源:http://riverbird.blogbus.com/logs/35992729.html

posted @ 2009-03-03 15:04 江边之鸟 阅读(797) | 评论 (0)编辑 收藏

现在找工作的事情,基本上集中在三点了.一是华为,现在基本已经定下来了,但是华为的管理相当严格,是唯一顾忌的事情;二是盛大,说是面试已通过,正在进行岗位评定,可能还需要过去一次.不过这里面用delphi作开发.三是一家新加坡公司,各方面都不错,而且可以直接从管理层做起,就等一个命题做完就可以了.但是却一直没有音讯.从下周周一,一定要开始工作啊.不能再等了,老婆孩子两张口,可是一直等着呢.


随机文章:

奇怪的消息 2009-03-03
C,Very Good 2007-03-07

收藏到:Del.icio.us





文章来源:http://riverbird.blogbus.com/logs/35989096.html

posted @ 2009-03-03 13:37 江边之鸟 阅读(618) | 评论 (0)编辑 收藏

2009年3月2日

safari 4出来了,和3.x版本相比,从界面上看,有比较大的改变.有点像是chrome的感觉.因为和chrome都在使用webkit引擎,可以用来作为备选浏览器.


收藏到:Del.icio.us





文章来源:http://riverbird.blogbus.com/logs/35942064.html

posted @ 2009-03-02 13:20 江边之鸟 阅读(603) | 评论 (0)编辑 收藏

版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
http://bangzhuzhongxin.blogbus.com/logs/24030921.html

Windows Live Writer是一款免费的桌面应用程序,您可以使用它在Blog中轻松发布丰富内容。通过它,您能够在本地电脑中撰写、发布、管理日志,您可前往http://get.live.com/writer/overview下载这款软件。

目前Bl...

收藏到:Del.icio.us





文章来源:http://riverbird.blogbus.com/logs/35937634.html

posted @ 2009-03-02 12:21 江边之鸟 阅读(922) | 评论 (0)编辑 收藏

live writer功能非常强大,应该让他来做更多的事情.


收藏到:Del.icio.us





文章来源:http://riverbird.blogbus.com/logs/35937584.html

posted @ 2009-03-02 12:20 江边之鸟 阅读(658) | 评论 (0)编辑 收藏

2009年3月1日

今天的好看簿好像出问题了,总是无法提交内容,真是让人郁闷。blogbus看起来是不错的东西,好像总部在杭州,搬家功能让人喜欢。


收藏到:Del.icio.us





文章来源:http://riverbird.blogbus.com/logs/35898677.html

posted @ 2009-03-01 14:21 江边之鸟 阅读(510) | 评论 (0)编辑 收藏

2009年2月28日

今天儿子随着他的妈妈从西安到杭州过来,这是他妈妈在火车上给他拍的照片,头发长的挺快的,小家伙做的也很稳当。亲爱的宝贝,明天爸爸就可以见到你了,呜哦!




收藏到:Del.icio.us





文章来源:http://riverbird.blogbus.com/logs/35859794.html

posted @ 2009-02-28 17:43 江边之鸟 阅读(430) | 评论 (0)编辑 收藏

2008年11月12日



收藏到:Del.icio.us





文章来源:http://riverbird.blogbus.com/logs/35860313.html

posted @ 2008-11-12 00:56 江边之鸟 阅读(428) | 评论 (0)编辑 收藏

2007年12月26日

python是支持多线程的,并且是native的线程。主要是通过thread和threading这两个模块来实现的。thread是比较底层的模 块,threading是对thread做了一些包装的,可以更加方便的被使用。这里需要提一下的是python对线程的支持还不够完善,不能利用多 CPU,但是下个版本的python中已经考虑改进这点,让我们拭目以待吧。
    threading模块里面主要是对一些线程的操作对象化了,创建了叫Thread的class。一般来说,使用线程有两种模式,一种是创建线程要执行的 函数,把这个函数传递进Thread对象里,让它来执行;另一种是直接从Thread继承,创建一个新的class,把线程执行的代码放到这个新的 class里。我们来看看这两种做法吧。

#-*- encoding: gb2312 -*-
import string, threading, time

def thread_main(a):
    
global count, mutex
    
# 获得线程名
    threadname = threading.currentThread().getName()
    
    
for x in xrange(0, int(a)):
        
# 取得锁
        mutex.acquire()
        count 
= count + 1
        
# 释放锁
        mutex.release()
        
print threadname, x, count
        time.sleep(
1)
    
def main(num):
    
global count, mutex
    threads 
= []
    
    count 
= 1
    
# 创建一个锁
    mutex = threading.Lock()
    
# 先创建线程对象
    for x in xrange(0, num):
        threads.append(threading.Thread(target
=thread_main, args=(10,)))
    
# 启动所有线程
    for t in threads:
        t.start()
    
# 主线程中等待所有子线程退出
    for t in threads:
        t.join()  
    
    
if __name__ == '__main__':
    num 
= 4
    
# 创建4个线程
    main(4)

上面的就是第一种做法,这种做法是很常见的,下面是另一种,曾经使用过Java的朋友应该很熟悉这种模式:

#-*- encoding: gb2312 -*-
import threading
import time

class Test(threading.Thread):
    
def __init__(self, num):
        threading.Thread.
__init__(self)
        self._run_num 
= num
    
    
def run(self):
        
global count, mutex
        threadname 
= threading.currentThread().getName()
    
        
for x in xrange(0, int(self._run_num)):
            mutex.acquire()
            count 
= count + 1
            mutex.release()
            
print threadname, x, count
            time.sleep(
1)

if __name__ == '__main__':
    
global count, mutex
    threads 
= []
    num 
= 4
    count 
= 1
    
# 创建锁
    mutex = threading.Lock()
    
# 创建线程对象
    for x in xrange(0, num):
        threads.append(Test(
10))
    
# 启动线程
    for t in threads:
        t.start()
    
# 等待子线程结束
    for t in threads:
        t.join() 

posted @ 2007-12-26 18:04 江边之鸟 阅读(10147) | 评论 (1)编辑 收藏

     摘要:   阅读全文

posted @ 2007-12-26 17:54 江边之鸟 阅读(684) | 评论 (0)编辑 收藏

     摘要:   阅读全文

posted @ 2007-12-26 17:35 江边之鸟 阅读(946) | 评论 (0)编辑 收藏

     摘要:   阅读全文

posted @ 2007-12-26 17:34 江边之鸟 阅读(7306) | 评论 (2)编辑 收藏

     摘要:   阅读全文

posted @ 2007-12-26 09:17 江边之鸟 阅读(1078) | 评论 (0)编辑 收藏

2007年12月25日

如果我们想让系统启动的时候就执行某个程序,windows系统和unix系统是不一样的,对于unix只需要将要执行的命令放到 rc.local中,系统重新启动的时候就可以加载了。windows就麻烦多了,如果你将程序放到启动组中,只有输入了密码后,程序才被执行,如果想在 系统一启动的时候就执行程序,必须使用nt服务。
python下如何使用nt服务,其实很简单。
下载python的win32支持。我使用的是:pywin32-202.win32-py2.3.exe安装好后就可以来写我们的服务了。
我们先来建立一个空的服务,建立test1.py这个文件,并写入如下代码:

# -*- coding: cp936 -*-
import win32serviceutil
import win32service
import win32event

class test1(win32serviceutil.ServiceFramework):
    _svc_name_ = "test_python"
    _svc_display_name_ = "test_python"
    def __init__(self, args):
        win32serviceutil.ServiceFramework.__init__(self, args)



        self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)

    def SvcStop(self):
        # 先告诉SCM停止这个过程
        self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
        # 设置事件
        win32event.SetEvent(self.hWaitStop)

    def SvcDoRun(self):
        # 等待服务被停止
        win32event.WaitForSingleObject(self.hWaitStop, win32event.INFINITE)

if __name__=='__main__':
    win32serviceutil.HandleCommandLine(test1)

这里注意,如果你需要更改文件名,比如将win32serviceutil.HandleCommandLine(test1)中的test1更改为你的文件名,同时class也需要和你的文件名一致,否则会出现服务不能启动的问题。
在命令窗口执行,test1.py可以看到帮助提示

C:\>test1.py
Usage: 'test1.py [options] install|update|remove|start [...]|stop|restart [...]|
debug [...]'
Options for 'install' and 'update' commands only:
 --username domain\username : The Username the service is to run under
 --password password : The password for the username
 --startup [manual|auto|disabled] : How the service starts, default = manual
 --interactive : Allow the service to interact with the desktop.

C:\>

安装我们的服务

[code:1:05b7353f1c]C:\>test1.py install
Installing service test_python to Python class C:\test1.test1
Service installed

C:\>

我们就可以用命令或者在控制面板-》管理工具-》服务中管理我们的服务了。在服务里面可以看到test_python这个服务,虽然这个服务什么都不做,但能启动和停止他。

posted @ 2007-12-25 15:12 江边之鸟 阅读(3848) | 评论 (0)编辑 收藏