国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
使用Python編寫免安裝運行時、以Windows后臺服務形式運行的WEB服務器

環(huán)境構建


安裝python2.7

安裝Setup Tools

在https://pypi.python.org/pypi/setuptools獲取安裝腳本的鏈接http://peak.telecommunity.com/dist/ez_setup.py,下載并運行


使用Setup Tools自動下載安裝webpy庫

運行"C:\Python27\Scripts>easy_install.exe web.py"


手動下載安裝pywin32庫

http://sourceforge.net/projects/pywin32/files/pywin32/Build%20218/


下載并安裝py2exe

編寫腳本


WebServer.py

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()

WindowsService.py

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)

setup.py

# mysetup.py

from distutils.core import setup

import py2exe


setup(service=["WindowsService"])

編譯獨立可執(zhí)行文件


python setup.py py2exe


安裝成windows服務并運行


sc create MyPythonServer binPath= f:\desktop\dist\WindowsService.exe


sc start MyPythonServer


在瀏覽器中訪問:”http://127.0.0.1:8089/visit/whatever“,結(jié)果顯示"you are visiting /visit/whatever"





Turbidsoul

setup(service=["WindowsService"], zipfile=None)

python setup.py py2exe -b 1

這樣編譯之后就只有一個exe文件,不會再有一大堆其他的文件。

本站僅提供存儲服務,所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權內(nèi)容,請點擊舉報
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
Python使用wxPython、py2exe編寫桌面程序
Python  pytest快速入門
聽說你剛開始寫 Python – Minghe
如何保護你的 Python 代碼 (一)—— 現(xiàn)有加密方案
Python 編寫Windows服務程序:將Python作為Windows服務啟動
Create win32 services using Python and py2exe...
更多類似文章 >>
生活服務
分享 收藏 導長圖 關注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服