作成しようとしている Windows システム サービスがあります。私は POS マシンのインターフェイスを作成しようとしているので、理想的にはシステム サービス内にこのコードを含めたいと考えています。ただし、いくつかの実験により、Windows システム サービスは基本的なタスクのみを実行し、他の反復は実行しないと考えるようになりました。
x 秒ごとに呼び出す必要がある別の関数があります。この追加関数は while ループですが、関数と win32 ループがシステム コールがうまく連携するのを待つことができません。以下のコードで詳しく説明します。
import win32service
import win32serviceutil
import win32event
class PySvc(win32serviceutil.ServiceFramework):
# net name
_svc_name_ = "test"
_svc_display_name_ = "test"
_svc_description_ = "Protects your computer."
def __init__(self, args):
win32serviceutil.ServiceFramework.__init__(self,args)
# create an event to listen for stop requests on
self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
# core logic of the service
def SvcDoRun(self):
# if the stop event hasn't been fired keep looping
while rc != win32event.WAIT_OBJECT_0:
# block for 60 seconds and listen for a stop event
rc = win32event.WaitForSingleObject(self.hWaitStop, 60000)
## I want to put an additional function that uses a while loop here.
## The service will not work correctly with additional iterations, inside or
## the above api calls.
## Due to the nature of the service and the api call above,
## this leads me to have to compile an additional .exe and somehow call that
## from the service.
# called when we're being shut down
def SvcStop(self):
# tell the SCM we're shutting down
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
# fire the stop event
win32event.SetEvent(self.hWaitStop)
if __name__ == '__main__':
win32serviceutil.HandleCommandLine(PySvc)
私の調査によると、何らかの方法で Windows システム サービスから .exe を呼び出す必要があることがわかりました。誰もこれを行う方法を知っていますか? 私は os.system を使用しようとしましたが、サブプロセス モジュールのバリアント コールは役に立ちませんでした。Windows は単にそれらを無視しているようです。何か案は?
編集:元の質問に戻る