Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

App hangs on test #409

Answered by skwzrd
skwzrd asked this question in Q&A
Discussion options

import os
import sys
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
import asyncio
from main import create_app
from configs import app_conf
async def test_endpoints():
 app = await create_app()
 results = []
 base_url = f'http://127.0.0.1:{app_conf.get("port")}'
 @app.before_serving
 async def startup():
 print("Starting up the app...")
 @app.after_serving
 async def shutdown():
 print("Shutting down the app...")
 await app.startup()
 for rule in app.url_map.iter_rules():
 print(rule)
 await app.shutdown()
if __name__ == "__main__":
 asyncio.run(test_endpoints())

This will print out

Starting up the app...
<all the routes>
Shutting down the app...

But it won't shut down on its own, and it hangs on that last line.

You must be logged in to vote

Databases were still connected... I found out which database it was by using something like

import sys
import traceback
for thread in threading.enumerate():
 if thread is not threading.main_thread():
 print(f'{thread.name=}')
 traceback.print_stack(sys._current_frames()[thread.ident])

I created this decorator for the test functions.

def close_all_dbs(func):
 @wraps(func)
 def wrapper(*args, **kwargs):
 func(*args, **kwargs)
 asyncio.run(db.pool_manager.close_pools())
 asyncio.run(db.pool_manager.close_pools())
 return wrapper

Replies: 1 comment

Comment options

Databases were still connected... I found out which database it was by using something like

import sys
import traceback
for thread in threading.enumerate():
 if thread is not threading.main_thread():
 print(f'{thread.name=}')
 traceback.print_stack(sys._current_frames()[thread.ident])

I created this decorator for the test functions.

def close_all_dbs(func):
 @wraps(func)
 def wrapper(*args, **kwargs):
 func(*args, **kwargs)
 asyncio.run(db.pool_manager.close_pools())
 asyncio.run(db.pool_manager.close_pools())
 return wrapper
You must be logged in to vote
0 replies
Answer selected by skwzrd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /