From 423cc3cfb8bc760a17085b16a3eb8aa3389f5878 Mon Sep 17 00:00:00 2001 From: Serafeim Papastefanos Date: Mon, 11 Nov 2024 23:09:24 +0200 Subject: [PATCH 1/6] Allow running on windows --- procrastinate/cli.py | 2 ++ .../contrib/django/management/commands/procrastinate.py | 5 ++++- procrastinate/signals.py | 9 ++++++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/procrastinate/cli.py b/procrastinate/cli.py index 169a29d0d..0910352f3 100644 --- a/procrastinate/cli.py +++ b/procrastinate/cli.py @@ -659,4 +659,6 @@ async def shell_(app: procrastinate.App, shell_command: list[str]): def main(): + if os.name == "nt": + asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) asyncio.run(cli(sys.argv[1:])) diff --git a/procrastinate/contrib/django/management/commands/procrastinate.py b/procrastinate/contrib/django/management/commands/procrastinate.py index 22bf59f17..2e6d5e035 100644 --- a/procrastinate/contrib/django/management/commands/procrastinate.py +++ b/procrastinate/contrib/django/management/commands/procrastinate.py @@ -1,7 +1,7 @@ from __future__ import annotations - import asyncio import contextlib +import os from django.core.management.base import BaseCommand @@ -24,6 +24,9 @@ def add_arguments(self, parser): suppressed_base_arguments = {"-v", "--version"} def handle(self, *args, **kwargs): + if os.name == 'nt': + asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) + kwargs = {k: v for k, v in kwargs.items() if k not in self._django_options} context = contextlib.nullcontext() diff --git a/procrastinate/signals.py b/procrastinate/signals.py index a88bb5bb2..338d51c66 100644 --- a/procrastinate/signals.py +++ b/procrastinate/signals.py @@ -3,10 +3,10 @@ import asyncio import contextlib import logging +import os import signal import threading from typing import Any, Callable - logger = logging.getLogger(__name__) # A few things about signals and asyncio: @@ -25,6 +25,13 @@ @contextlib.contextmanager def on_stop(callback: Callable[[], None]): + if os.name == "nt": + logger.warning( + "Skipping signal handling, does not work on Windows", + extra={"action": "skip_signal_handlers"}, + ) + yield + return if threading.current_thread() is not threading.main_thread(): logger.warning( "Skipping signal handling, because this is not the main thread", From aa87b4716f97dbbd00bc7ac93a61b648ea388ef9 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 11 Nov 2024 21:12:23 +0000 Subject: [PATCH 2/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../contrib/django/management/commands/procrastinate.py | 3 ++- procrastinate/signals.py | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/procrastinate/contrib/django/management/commands/procrastinate.py b/procrastinate/contrib/django/management/commands/procrastinate.py index 2e6d5e035..1b73eb185 100644 --- a/procrastinate/contrib/django/management/commands/procrastinate.py +++ b/procrastinate/contrib/django/management/commands/procrastinate.py @@ -1,4 +1,5 @@ from __future__ import annotations + import asyncio import contextlib import os @@ -24,7 +25,7 @@ def add_arguments(self, parser): suppressed_base_arguments = {"-v", "--version"} def handle(self, *args, **kwargs): - if os.name == 'nt': + if os.name == "nt": asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) kwargs = {k: v for k, v in kwargs.items() if k not in self._django_options} diff --git a/procrastinate/signals.py b/procrastinate/signals.py index 338d51c66..e13446e37 100644 --- a/procrastinate/signals.py +++ b/procrastinate/signals.py @@ -7,6 +7,7 @@ import signal import threading from typing import Any, Callable + logger = logging.getLogger(__name__) # A few things about signals and asyncio: From 58ecc40e86d4c4f35b3933bdeb10c13675cc1429 Mon Sep 17 00:00:00 2001 From: Serafeim Papastefanos Date: Wed, 13 Nov 2024 10:11:11 +0200 Subject: [PATCH 3/6] Add docs for windows --- docs/howto/basics.md | 1 + docs/howto/basics/windows.md | 15 +++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 docs/howto/basics/windows.md diff --git a/docs/howto/basics.md b/docs/howto/basics.md index 4fd2fe154..dbe638497 100644 --- a/docs/howto/basics.md +++ b/docs/howto/basics.md @@ -12,4 +12,5 @@ basics/tasks basics/defer basics/worker basics/command_line +basics/windows ::: diff --git a/docs/howto/basics/windows.md b/docs/howto/basics/windows.md new file mode 100644 index 000000000..b9fe8a44e --- /dev/null +++ b/docs/howto/basics/windows.md @@ -0,0 +1,15 @@ +# Running on Windows + +Procrastinate has been tested and is known to work on Windows. However, there are +a few things to keep in mind: + +- Due to the way signals are implemented on Windows (in short, they are not fully supported), + the worker will not be able to gracefully stop when receiving a `SIGINT` or `SIGTERM` signal + as described in the {doc}`../production/retry_stalled_jobs` guide. This means that any running + jobs will be halted abruptly. + +- We do not use windows for running Procrastinate in production, so we may not + be aware of all the issues that may arise. + +Given these limitations, we strongly advise using a Unix-like system for running Procrastinate +in production. Windows should primarily be used for development purposes only. From 4890e362795693a9ac130581d19595b6772bcb22 Mon Sep 17 00:00:00 2001 From: Serafeim Papastefanos Date: Wed, 13 Nov 2024 13:24:46 +0200 Subject: [PATCH 4/6] Update docs/howto/basics/windows.md Co-authored-by: Joachim Jablon --- docs/howto/basics/windows.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/howto/basics/windows.md b/docs/howto/basics/windows.md index b9fe8a44e..43cbf27fc 100644 --- a/docs/howto/basics/windows.md +++ b/docs/howto/basics/windows.md @@ -1,7 +1,7 @@ # Running on Windows -Procrastinate has been tested and is known to work on Windows. However, there are -a few things to keep in mind: +Procrastinate has been manually tested and is known to work on Windows. However, +there are a few things to keep in mind: - Due to the way signals are implemented on Windows (in short, they are not fully supported), the worker will not be able to gracefully stop when receiving a `SIGINT` or `SIGTERM` signal From 518e752854e08b00d962a980d51dc51dfacfc6f3 Mon Sep 17 00:00:00 2001 From: Serafeim Papastefanos Date: Wed, 13 Nov 2024 13:24:59 +0200 Subject: [PATCH 5/6] Update docs/howto/basics/windows.md Co-authored-by: Joachim Jablon --- docs/howto/basics/windows.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/howto/basics/windows.md b/docs/howto/basics/windows.md index 43cbf27fc..5b0cfc43a 100644 --- a/docs/howto/basics/windows.md +++ b/docs/howto/basics/windows.md @@ -11,5 +11,9 @@ there are a few things to keep in mind: - We do not use windows for running Procrastinate in production, so we may not be aware of all the issues that may arise. +- There are no automated tests in place for windows, so it's possible you encounter + bugs. If you know what needs to be fixed, we accept + [pull requests](https://github.com/procrastinate-org/procrastinate/pulls). + Thank you! Given these limitations, we strongly advise using a Unix-like system for running Procrastinate in production. Windows should primarily be used for development purposes only. From 2262c99041507d02ed7164b7efbefb31eba5489f Mon Sep 17 00:00:00 2001 From: Serafeim Papastefanos Date: Mon, 25 Nov 2024 22:45:58 +0200 Subject: [PATCH 6/6] Update windows.md to add a newline --- docs/howto/basics/windows.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/howto/basics/windows.md b/docs/howto/basics/windows.md index 5b0cfc43a..32155e651 100644 --- a/docs/howto/basics/windows.md +++ b/docs/howto/basics/windows.md @@ -15,5 +15,6 @@ there are a few things to keep in mind: bugs. If you know what needs to be fixed, we accept [pull requests](https://github.com/procrastinate-org/procrastinate/pulls). Thank you! + Given these limitations, we strongly advise using a Unix-like system for running Procrastinate in production. Windows should primarily be used for development purposes only.