diff --git a/beanie/__init__.py b/beanie/__init__.py index be2c785c..6485a834 100644 --- a/beanie/__init__.py +++ b/beanie/__init__.py @@ -32,7 +32,7 @@ from beanie.odm.utils.init import init_beanie from beanie.odm.views import View -__version__ = "1.23.4" +__version__ = "1.23.5" __all__ = [ # ODM "Document", diff --git a/beanie/odm/utils/init.py b/beanie/odm/utils/init.py index f17886e1..a70b905b 100644 --- a/beanie/odm/utils/init.py +++ b/beanie/odm/utils/init.py @@ -64,6 +64,7 @@ def __init__( ] = None, allow_index_dropping: bool = False, recreate_views: bool = False, + multiprocessing_mode: bool = False, ): """ Beanie initializer @@ -74,8 +75,12 @@ def __init__( or strings with dot separated paths :param allow_index_dropping: bool - if index dropping is allowed. Default False + :param recreate_views: bool - if views should be recreated. Default False + :param multiprocessing_mode: bool - if multiprocessing mode is on + it will patch the motor client to use process's event loop. :return: None """ + self.inited_classes: List[Type] = [] self.allow_index_dropping = allow_index_dropping self.recreate_views = recreate_views @@ -98,6 +103,9 @@ def __init__( self.database: AsyncIOMotorDatabase = database + if multiprocessing_mode: + self.database.client.get_io_loop = self.database.get_io_loop + sort_order = { ModelType.UnionDoc: 0, ModelType.Document: 1, @@ -725,6 +733,7 @@ async def init_beanie( ] = None, allow_index_dropping: bool = False, recreate_views: bool = False, + multiprocessing_mode: bool = False, ): """ Beanie initialization @@ -735,6 +744,9 @@ async def init_beanie( or strings with dot separated paths :param allow_index_dropping: bool - if index dropping is allowed. Default False + :param recreate_views: bool - if views should be recreated. Default False + :param multiprocessing_mode: bool - if multiprocessing mode is on + it will patch the motor client to use process's event loop. Default False :return: None """ @@ -744,4 +756,5 @@ async def init_beanie( document_models=document_models, allow_index_dropping=allow_index_dropping, recreate_views=recreate_views, + multiprocessing_mode=multiprocessing_mode, ) diff --git a/docs/changelog.md b/docs/changelog.md index 191ac6bb..4c7f911c 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -2,6 +2,14 @@ Beanie project +## [1.23.5] - 2023-11-12 + +### Multiprocessing Mode For Init +- Author - [Roman Right](https://github.com/roman-right) +- PR + +[1.23.5]: https://pypi.org/project/beanie/1.23.5 + ## [1.23.4] - 2023-11-12 ### Args For `get_model_dump` diff --git a/pyproject.toml b/pyproject.toml index 190ed6ad..2fea59d0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "flit_core.buildapi" [project] name = "beanie" -version = "1.23.4" +version = "1.23.5" description = "Asynchronous Python ODM for MongoDB" readme = "README.md" requires-python = ">=3.7,<4.0" diff --git a/tests/test_beanie.py b/tests/test_beanie.py index 675c5e17..25076897 100644 --- a/tests/test_beanie.py +++ b/tests/test_beanie.py @@ -2,4 +2,4 @@ def test_version(): - assert __version__ == "1.23.4" + assert __version__ == "1.23.5"