feat: add main_sync wrapper for asyncio compatibility
All checks were successful
Docker CI/CD / Docker Build and Push to Docker Hub (push) Successful in 10m11s
All checks were successful
Docker CI/CD / Docker Build and Push to Docker Hub (push) Successful in 10m11s
Refactored the main execution pathway to introduce a `main_sync` function that wraps the existing asynchronous `main` function, facilitating compatibility with environments that necessitate or prefer synchronous execution. This change enhances the bot's flexibility in various deployment scenarios without altering the core asynchronous functionality. In addition, expanded the exception handling in `get_version` to catch all exceptions instead of limiting to `DistributionNotFound`. This broadens the robustness of version retrieval, ensuring the application can gracefully handle unexpected issues during version lookup. Whitespace adjustments improve code readability by clearly separating function definitions. These adjustments contribute to the maintainability and operability of the application, allowing for broader usage contexts and easier integration into diverse environments.
This commit is contained in:
parent
bc06f8939a
commit
02887b9336
1 changed files with 9 additions and 2 deletions
|
@ -7,16 +7,19 @@ import signal
|
||||||
import asyncio
|
import asyncio
|
||||||
import importlib.metadata
|
import importlib.metadata
|
||||||
|
|
||||||
|
|
||||||
def sigterm_handler(_signo, _stack_frame):
|
def sigterm_handler(_signo, _stack_frame):
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
|
|
||||||
def get_version():
|
def get_version():
|
||||||
try:
|
try:
|
||||||
package_version = importlib.metadata.version("matrix_gptbot")
|
package_version = importlib.metadata.version("matrix_gptbot")
|
||||||
except pkg_resources.DistributionNotFound:
|
except Exception:
|
||||||
return None
|
return None
|
||||||
return package_version
|
return package_version
|
||||||
|
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
# Parse command line arguments
|
# Parse command line arguments
|
||||||
parser = ArgumentParser()
|
parser = ArgumentParser()
|
||||||
|
@ -59,5 +62,9 @@ async def main():
|
||||||
print("Received SIGTERM - exiting...")
|
print("Received SIGTERM - exiting...")
|
||||||
|
|
||||||
|
|
||||||
|
def main_sync():
|
||||||
|
asyncio.run(main())
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
asyncio.get_event_loop().run_until_complete(main())
|
main_sync()
|
||||||
|
|
Loading…
Reference in a new issue