在https://pypi.python.org/pypi/setuptools獲取安裝腳本的連接http://peak.telecommunity.com/dist/ez_setup.py,下載並運行 python
運行"C:\Python27\Scripts>easy_install.exe web.py" web
http://sourceforge.net/projects/pywin32/files/pywin32/Build%20218/ windows
import web class WebServer(web.auto_application): def run(self, port, *middleware): func = self.wsgifunc(*middleware) return web.httpserver.runsimple(func, ('0.0.0.0', port)) app = WebServer() ##########################web services class hello(app.page): def GET(self): return 'Hello,world' class visit(app.page): path = '/visit/.*' def GET(self): return 'you are visiting '+web.ctx.path ########################## def main(): app.run(port=8089) if __name__ == "__main__": main()
import win32serviceutil import win32service import win32event import thread def log(message): logger = file("e:\log.txt","a") logger.write(message+"\r\n") logger.close() class WindowsService(win32serviceutil.ServiceFramework): #這兩行必須 _svc_name_ = "" _svc_display_name_ = "" def __init__(self, args): win32serviceutil.ServiceFramework.__init__(self, args) self.hWaitStop = win32event.CreateEvent(None, 0, 0, None) def SvcStop(self): self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) win32event.SetEvent(self.hWaitStop) def SvcDoRun(self): import WebServer thread.start_new(WebServer.main, ()) win32event.WaitForSingleObject(self.hWaitStop, win32event.INFINITE)
# mysetup.py from distutils.core import setup import py2exe setup(service=["WindowsService"])
python setup.py py2exe 瀏覽器
sc create MyPythonServer binPath= f:\desktop\dist\WindowsService.exe app
sc start MyPythonServer python2.7
在瀏覽器中訪問:」http://127.0.0.1:8089/visit/whatever「,結果顯示"you are visiting /visit/whatever" ui
python訪問REST
用Python實現CRUD功能REST服務
Getting RESTful with web.py
Web.py初探:安裝與HelloWorld
使用py2exe製做免運行時的可執行文件
Web.py初探:安裝與HelloWorld
Create win32 services using Python and py2exe
spa