python處理跨平台應用

2021-07-03 19:29:12 字數 2505 閱讀 5321

在工作中處理應用程式維護,遇到很多問題終於還是搞定了。記下,後面補充具體問題。

#-*- coding=gbk -*-

import psutil

import re

import sys

import string

import time

import subprocess

def startprocess(cwd):

print cwd;

processname = ["ctpd.exe", "mdd.exe", "cf_serverd.exe", "trade_serverd.exe", "frontd.exe"];

processxml = dict((("frontd.exe", "front.xml"), ("trade_serverd.exe", "trade_server.xml"), ("cf_serverd.exe", "cf_server.xml"), ("mdd.exe", "md.xml"), ("ctpd.exe", "server_ctp.xml")));

for k in processname:

v = processxml[k];

processinfo = cwd+"\\"+k+" "+cwd+"\\"+v;

#processinfo = k+" "+v;

print processinfo

try:

p = subprocess.popen(processinfo, stdout=subprocess.pipe);

print "%s starts successful" %k;

time.sleep(10);

except exception, p:

print "(%s, %s) is not find!" %(k, v)

def controlprocess(hour=0, interval=5):

processname = ["ctpd.exe", "mdd.exe", "cf_serverd.exe", "trade_serverd.exe", "frontd.exe", "front_testd.exe"];

while 1:

tmphour = string.atoi(time.strftime("%h", time.localtime()))

if tmphour == hour:

print "當前時間為:%s, 伺服器重啟中..." %time.ctime()

#設定下一次終止時間

hour = tmphour;

if hour >= 24:

hour = hour-24;

#終止程序

for p in processname:

killprocess(p);

#啟動程序

startprocess("d:\\code\\zq_sim_debug\\bin");

#設定休眠半個小時

time.sleep(10)

print "距離下一次重啟還有%d個小時" %(hour-tmphour)

def killprocess(x):

for p in psutil.process_iter():

#print(p)

#print "pid is:", p.pid

pitem = psutil.process(p.pid)

try:

if (pitem.name() == x):

pitem.kill();

print "kill name ", x;

except exception, p:

print "the pid %d is no name" % p.pid

#print "name:", sys.argv[0]

#for i in range(1, len(sys.argv)):

# print "parma:", i, sys.argv[i]

if __name__ == "__main__":

print "首次重啟伺服器時間設定(例如00:00:00)"

#inputtime = input("請輸入:");

inputtime = raw_input("請輸入:");

print "設定迴圈間隔啟動伺服器時間(單位:小時)"

inputinterval = raw_input("請輸入:");

strhour, min_sec = inputtime.split(':', 1);

hour = string.atoi(strhour);

interval = string.atoi(inputinterval);

#print "啟動時間為:", hour;

#print "間隔時間為:", interval

controlprocess(hour, interval)

#startprocess("d:\\code\\zq_sim_debug\\bin")

跨平台移動應用開發

來自於iotashan的一篇blog 有一定的參考價值。關於如何選擇移動平台開發工具,作者提出了四點意見 must perform,even last gen phones 支援最新的手機是必須的,而且還必須支援最新版sdk must support at least iphone android,...

cordova vue cli構建跨平台應用

npm i cordova g 複製 cordova create 專案名稱 複製 可新增的平台 android ios blackberry 10 os x ubuntu windows wp8 執行前需要配置平台的sdk,配置方法就不詳細描述了,官網都有詳細的說明。cordova platfor...

C預處理跨平台

include 不同的平台下引入不同的標頭檔案 if win32 識別windows平台 include elif linux 識別linux平台 include endif intmain 要開發乙個c語言程式,讓它暫停 5 秒以後再輸出內容,並且要求跨平台,在 windows 和 linux 下...