Mode

Latest version: v4.4.0

Safety actively analyzes 629564 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 8 of 15

2.0.0

=====
:release-date: 2018-11-02 9:12 A.M PST
:release-by: Ask Solem (:github_user:`ask`)

- Services now create the event loop on demand.

This means the event loop is no longer created in `Service.__init__`
so that services can be defined at module scope without initializing
the loop.

This makes the ``ServiceProxy`` pattern redundant for most use cases.

- Adds ``.utils.compat.current_task`` as alias for
:mod:`asyncio.current_task`.

- Adds support for contextvars in Python 3.6 using :pypi:`aiocontextvars`.

In mode services you can now use :mod:`contextvars` module even
on Python 3.6, thanks to the work of :github_user:`fantix`.

.. _version-1.18.2:

1.18.2

======
:release-date: 2018-11-30 6:23 P.M PDT
:release-by: Ask Solem (:github_user:`ask`)

- Worker: SIGUSR1 cry handler: Fixed crash when coroutine does not have
``__name__`` attribute.

.. _version-1.18.1:

1.18.1

======
:release-date: 2018-10-03 2:49 P.M PDT
:release-by: Ask Solem (:github_user:`ask`)

- **Service**: ``Service.from_awaitable(coro)`` improvements.

The resulting ``service.start`` will now:

+ Convert awaitable to :class:`asyncio.Task`.
+ Wait for task to complete.

then ``service.stop`` will:

+ Cancel the task.

This ensures an ``asyncio.sleep(10.0)`` within can be
cancelled. If you need some operation to absolutely finish you must
use `asyncio.shield`.

- **Utils**: ``cached_property`` adds new ``.is_set(o)`` method on descriptor

This can be used to test for the attribute having been cached/used.

If you have a class with a ``cached_property``:

.. sourcecode:: python

from mode.utils.objects import cached_property

class X:

cached_property
def foo(self):
return 42

x = X()
print(x.foo)

From an instance you can now check if the property was accessed:

.. sourcecode:: python

if type(x).foo.is_set(x):
print(f'Someone accessed x.foo and it was cached as: {x.foo}')

.. _version-1.18.0:

1.18.0

======
:release-date: 2018-10-02 3:32 P.M PDT
:release-by: Ask Solem (:github_user:`ask`)

- **Worker**: Fixed error when starting :pypi:`aioconsole` on ``--debug``

The worker would crash with:

.. sourcecode:: text

TypeError: Use `self.add_context(ctx)` for non-async context

when started with the ``--debug`` flag.

- **Worker**: New ``daemon`` argument controls shutdown of worker.

When the flag is enabled, the default, the worker will not shut
down until the worker instance is either explicitly stopped, or
it receives a terminating process signal (``SIGINT``/``SIGTERM``/etc.)

When disabled, the worker for the given service will shut down as soon as
``await service.start()`` returns.

You can think of it as a flag for daemons, but one that doesn't actually
do any of the UNIX daemonization stuff (detaching, etc.). It merely
means the worker continues to run in the background until stopped by
signal.

- **Service**: Added class method: ``Service.from_awaitable``.

This can be used to create a service out of any coroutine
or :class:`~typing.Awaitable`:

.. sourcecode:: python

from mode import Service, Worker

async def me(interval=1.0):
print('ME STARTING')
await asyncio.sleep(interval)
print('ME STOPPING')

def run_worker(interval=1.0):
coro = me(interval=1.0)
Worker(Service.from_awaitable(coro)).execute_from_commandline()

if __name__ == '__main__':
run_worker()

.. note::

Using a service with ``await self.sleep(1.0)`` is often not what
you want, as stopping the service will have to wait for the sleep
to finish.

``Service.from_awaitable`` is as such a last resort for cases
where you're provided a coroutine you cannot implement as a service.

``Service.sleep()`` is useful as it will stop sleeping immediately
if the service is stopped:

class Me(Service):

async def on_start(self) -> None:
await self.sleep(1.0)

- **Service**: New method ``_repr_name`` can be used to override the service
class name used in ``repr(service)``.

.. _version-1.17.3:

1.17.3

======
:release-date: 2018-09-18 4:00 P.M PDT
:release-by: Ask Solem (:github_user:`ask`)

- Service: New attribute ``mundane_level`` decides the logging level
of mundane logging events such as "[X] Starting...", for starting/stopping
and tasks being cancelled.

The value for this must be a logger level name, and is ``"info"`` by
default.

If logging for a service is noisy at info-level, you can move it
to debug level by setting this attribute to ``"debug"``:

.. sourcecode:: python

class X(Service):
mundane_level = 'debug'

.. _version-1.17.2:

1.17.2

======
:release-date: 2018-09-17 3:00 P.M PDT
:release-by: Ask Solem (:github_user:`ask`)

- Removed and fixed import from ``collections`` that will be moved
to ``collections.abc`` in Python 3.8.

This also silences a ``DeprecationWarning`` that was being emitted
on Python 3.7.

- Type annotations now passing checks on :pypi:`mypy` 0.630.

.. _version-1.17.1:

Page 8 of 15

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.