This is an automated email from the ASF dual-hosted git repository.
gcruz pushed a commit to branch gc/8574
in repository https://gitbox.apache.org/repos/asf/allura.git
The following commit(s) were added to refs/heads/gc/8574 by this push:
new d5d56350e [#8574] removed the async function start_server in favor a
more simple approach to keep the server running
d5d56350e is described below
commit d5d56350e57f1ac2715aa4f90c26be3fc255d016
Author: Guillermo Cruz <[email protected]>
AuthorDate: Tue Feb 4 15:51:02 2025 -0700
[#8574] removed the async function start_server in favor a more simple
approach to keep the server running
---
Allura/allura/command/smtp_server.py | 26 ++++++++++----------------
1 file changed, 10 insertions(+), 16 deletions(-)
diff --git a/Allura/allura/command/smtp_server.py
b/Allura/allura/command/smtp_server.py
index 3a1b07e42..5d42e5391 100644
--- a/Allura/allura/command/smtp_server.py
+++ b/Allura/allura/command/smtp_server.py
@@ -27,16 +27,9 @@
from aiosmtpd.controller import Controller
import asyncio
from tg.wsgiapp import RequestLocals
+import time
-async def start_server(loop):
- handler = MailServer()
- hostname = tg.config.get('forgemail.host', '0.0.0.0')
- port = asint(tg.config.get('forgemail.port', 8825))
- controller = Controller(handler, hostname=hostname, port=port)
- controller.start()
-
-
class SMTPServerCommand(base.Command):
min_args = 1
max_args = 1
@@ -50,14 +43,14 @@ class SMTPServerCommand(base.Command):
def command(self):
faulthandler.enable()
self.basic_setup()
- loop = asyncio.get_event_loop()
- task = loop.create_task(start_server(loop=loop))
- try:
- loop.run_forever()
- except KeyboardInterrupt:
- task.cancel()
- finally:
- loop.close()
+ handler = MailServer()
+ hostname = tg.config.get('forgemail.host', '0.0.0.0')
+ port = asint(tg.config.get('forgemail.port', 8825))
+ controller = Controller(handler, hostname=hostname, port=port)
+ controller.start()
+ while True:
+ time.sleep(100000)
+
class MailServer:
async def handle_DATA(self, server, session, envelope):
@@ -68,6 +61,7 @@ async def handle_DATA(self, server, session, envelope):
data = envelope.content
base.log.info('Msg Received from %s for %s', mailfrom, rcpttos)
base.log.info(' (%d bytes)', len(data))
+ # pass the app_globals into the request context again because it's
in a different thread
tgl = RequestLocals()
tgl.tmpl_context = EmptyClass()
tgl.app_globals = tg.app_globals