diff options
author | Erik Johnston <erik@matrix.org> | 2022-03-08 13:23:18 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-08 13:23:18 +0000 |
commit | 2ce27a24fe29104ca54e0a879c7ad37d88a3fc69 (patch) | |
tree | 23a2ace0464dfc2fcad8b333fe6bbe93359901fc /synapse/__init__.py | |
parent | Do not return allowed_room_ids from /hierarchy response. (#12175) (diff) | |
download | synapse-2ce27a24fe29104ca54e0a879c7ad37d88a3fc69.tar.xz |
Add experimental environment variable to enable asyncio reactor (#12135)
Diffstat (limited to 'synapse/__init__.py')
-rw-r--r-- | synapse/__init__.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/synapse/__init__.py b/synapse/__init__.py index b21e1ed0f3..674acc7135 100644 --- a/synapse/__init__.py +++ b/synapse/__init__.py @@ -25,6 +25,27 @@ if sys.version_info < (3, 7): print("Synapse requires Python 3.7 or above.") sys.exit(1) +# Allow using the asyncio reactor via env var. +if bool(os.environ.get("SYNAPSE_ASYNC_IO_REACTOR", False)): + try: + from incremental import Version + + import twisted + + # We need a bugfix that is included in Twisted 21.2.0: + # https://twistedmatrix.com/trac/ticket/9787 + if twisted.version < Version("Twisted", 21, 2, 0): + print("Using asyncio reactor requires Twisted>=21.2.0") + sys.exit(1) + + import asyncio + + from twisted.internet import asyncioreactor + + asyncioreactor.install(asyncio.get_event_loop()) + except ImportError: + pass + # Twisted and canonicaljson will fail to import when this file is executed to # get the __version__ during a fresh install. That's OK and subsequent calls to # actually start Synapse will import these libraries fine. |