我的脚本/程序由 main.py 组成;submethod1.py, submethod2.py 在子目录中;临时文件的第二个子目录;一个用于记录的 txt 文件 我正在努力将它作为服务运行一周。
PyWin32 给了我 Error 1053: The service did not respond to the start or control request in a timely fashion
. NSSM 只是Unexpected status SERVICE_STOPPED in response to START control
在 stdout 中写了这个,什么都没有。如何理解服务有什么问题?我无法正确调试它。它可以完美地独立运行,我在 IDE 中对其进行了调试。
import configparser
from script.sql import *
def app():
# reading .ini file
print (os.getcwd())
default_file = os.getcwd()+ r"/config.ini"
config = configparser.ConfigParser()
config.read (default_file)
path = config.get ("XLS", "dir")
file_1 = path + "\\" + config.get ("XLS", "workbook1")
file_2 = path + "\\" + config.get ("XLS", "workbook2")
file_3 = path + "\\" + config.get ("XLS", "workbook3")
usr = config.get ("SQL", "user")
pwd = config.get ("SQL", "password")
hst = config.get ("SQL", "host")
db = config.get ("SQL", "database")
pt = config.get ("SQL", "port")
ssl_cert = config.get ("SQL", "ssl_cert")
ssl_ca = config.get ("SQL", "ssl_ca")
ssl_key = config.get ("SQL", "ssl_key")
enc = config.get ("SQL", "encoding")
sql_config = "mysql+pymysql://" + usr + ":" + pwd + "@" + hst + ":" + pt + "/" + db + "?" + ssl_cert + "&" + \
ssl_ca + "&" + ssl_key + "&" + enc
if (os.path.isfile (file_1) == True or os.path.isfile (file_2) == True or os.path.isfile (file_3) == True):
SQL.sqlconnect (sql_config)
if (os.path.isfile (file_1) == True):
XLS.xls_wrk (file_1)
df_xls_1 = XLS.table_xls (file_1)
df_sql_1 = SQL.table_sql (file_1, sql_config)
if (df_sql_1.equals (df_xls_1) == False):
try:
SQL.sql_import (file_1, sql_config)
except:
SQL.table_trunc (file_1, sql_config)
if (os.path.isfile (file_2) == True):
XLS.xls_wrk (file_2)
df_xls_2 = XLS.table_xls (file_2)
df_sql_2 = SQL.table_sql (file_2, sql_config)
if (df_sql_2.equals (df_xls_2) == False):
try:
SQL.sql_import (file_2, sql_config)
except:
SQL.table_trunc (file_2, sql_config)
if (os.path.isfile (file_3) == True):
XLS.xls_wrk (file_3)
df_xls_3 = XLS.table_xls (file_3)
df_sql_3 = SQL.table_sql (file_3, sql_config)
if (df_sql_3.equals (df_xls_3) == False):
try:
SQL.sql_import (file_3, sql_config)
except:
SQL.table_trunc (file_3, sql_config)
SQL.con_close (sql_config)
else:
with open (os.getcwd () + r"\PyXLSQL.log", "a+") as text_file:
print (f"{str(datetime.datetime.now()).split('.')[0]} - Excel workbooks not found in dir {path}",
file=text_file)
if __name__ == '__main__':
app()
我使用了所有 python windows 服务无法启动的工作模板{error 1053}
有什么问题?有一个循环,或者我可以添加一个循环来检查 RunSvc 部分中任何 *xls 文件的目录。无论如何,在尝试将其作为服务运行后没有有用的调试信息。
更新:
Debugging service PyTest - press Ctrl+C to stop.
Info 0x40001002 - The PyTest service has started.
Error 0xC0000003 - The instance's SvcRun() method failed
<Error getting traceback - traceback.print_exception() failed
(null): (null)
使用另一个模板将脚本作为服务运行。