diff options
author | Alex Grönholm <alex.gronholm@nextday.fi> | 2021-01-19 12:45:53 +0200 |
---|---|---|
committer | Alex Grönholm <alex.gronholm@nextday.fi> | 2021-01-19 12:45:53 +0200 |
commit | b79343dc671ed9ea379d3da5d70698851ec0460e (patch) | |
tree | 96223f5c6bc418244c38ea5aa8acbe03403bb7e5 | |
parent | ae4d997ab9238cbd95a097e8633cae6197623fe3 (diff) | |
download | apscheduler-b79343dc671ed9ea379d3da5d70698851ec0460e.tar.gz |
Made the schedulers explicitly raise a descriptive TypeError
-rw-r--r-- | apscheduler/schedulers/base.py | 5 | ||||
-rw-r--r-- | docs/versionhistory.rst | 1 | ||||
-rw-r--r-- | tests/test_schedulers.py | 4 |
3 files changed, 10 insertions, 0 deletions
diff --git a/apscheduler/schedulers/base.py b/apscheduler/schedulers/base.py index a7aa17e..3dfb743 100644 --- a/apscheduler/schedulers/base.py +++ b/apscheduler/schedulers/base.py @@ -86,6 +86,11 @@ class BaseScheduler(six.with_metaclass(ABCMeta)): self.state = STATE_STOPPED self.configure(gconfig, **options) + def __getstate__(self): + raise TypeError("Schedulers cannot be serialized. Ensure that you are not passing a " + "scheduler instance as an argument to a job, or scheduling an instance " + "method where the instance contains a scheduler as an attribute.") + def configure(self, gconfig={}, prefix='apscheduler.', **options): """ Reconfigures the scheduler with the given options. diff --git a/docs/versionhistory.rst b/docs/versionhistory.rst index 8cca199..40e6328 100644 --- a/docs/versionhistory.rst +++ b/docs/versionhistory.rst @@ -16,6 +16,7 @@ APScheduler, see the :doc:`migration section <migration>`. to prevent situations where the scheduler won't run because it's using a different event loop than then one currently running * Made it possible to create weak references to ``Job`` instances +* Made the schedulers explicitly raise a descriptive ``TypeError`` when serialization is attempted * Fixed Zookeeper job store using backslashes instead of forward slashes for paths on Windows (PR by Laurel-rao) * Fixed deprecation warnings on the MongoDB job store and increased the minimum PyMongo diff --git a/tests/test_schedulers.py b/tests/test_schedulers.py index 7bd2301..515b824 100644 --- a/tests/test_schedulers.py +++ b/tests/test_schedulers.py @@ -1,4 +1,5 @@ import logging +import pickle from datetime import datetime, timedelta from threading import Thread @@ -772,6 +773,9 @@ Jobstore other: assert len(scheduler_events) == 1 assert scheduler_events[0].scheduled_run_times == [freeze_time.get(scheduler.timezone)] + def test_serialize_scheduler(self, scheduler): + pytest.raises(TypeError, pickle.dumps, scheduler).match('Schedulers cannot be serialized') + class TestProcessJobs(object): @pytest.fixture |