Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request additional time when stopping a windows service #2489

Open
l0ner opened this issue Jul 2, 2024 · 2 comments
Open

Request additional time when stopping a windows service #2489

l0ner opened this issue Jul 2, 2024 · 2 comments

Comments

@l0ner
Copy link

l0ner commented Jul 2, 2024

Hi

I have written a windows service that periodically processes a lot data. Because of how it works and what it does, when a stop gets requested it needs to finish processing, and only then it can stop.

Currently if i request the service to stop while it is processing the data the windows will throw an error sayig that the service did not stop in timely manner.

In c# one can call RequestAdditionalTime() function, to keep the windows happy while the service is stopping. Can this be somehow be achieved in cx_freeze generated windows services?

This could also be useful when starting a service that takes a long time for initialization.

@marcelotduarte
Copy link
Owner

In c# one can call RequestAdditionalTime() function, to keep the windows happy while the service is stopping. Can this be somehow be achieved in cx_freeze generated windows services?

We can implement this. Can you do it (if you use C) or at least find the equivalent function in C so I can implement it?

@l0ner
Copy link
Author

l0ner commented Jul 31, 2024

Unfortunately I'm not a C programmer.

But i guess the equivalent functionality could be achieved by calling SetServiceStatus with value of SERVICE_STOP_PENDING repedately.

I have since implemented my service using the win32service library, and doing this works:

while has_running_tasks():
	logger.info("Waiting for still running tasks to finish")
	time.sleep(5)
	self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)

The windows still will report that the service "did not stop in a timely manner" (but will take more time than normally), and will not kill it forcefully, allowing the service to stop properely (i had one taks that took additional 30 minutes to complete after asking windows to stop the service and the task finished normally and then the service did stop).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants