| 
									
										
										
										
											2024-12-31 11:42:51 +08:00
										 |  |  | import os | 
					
						
							|  |  |  | import sys | 
					
						
							| 
									
										
										
										
											2024-12-18 09:05:31 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def is_db_command(): | 
					
						
							|  |  |  |     if len(sys.argv) > 1 and sys.argv[0].endswith("flask") and sys.argv[1] == "db": | 
					
						
							|  |  |  |         return True | 
					
						
							|  |  |  |     return False | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | # create app | 
					
						
							| 
									
										
										
										
											2024-12-18 09:05:31 +08:00
										 |  |  | if is_db_command(): | 
					
						
							|  |  |  |     from app_factory import create_migrations_app | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     app = create_migrations_app() | 
					
						
							|  |  |  | else: | 
					
						
							| 
									
										
										
										
											2025-01-02 15:59:30 +08:00
										 |  |  |     # It seems that JetBrains Python debugger does not work well with gevent, | 
					
						
							|  |  |  |     # so we need to disable gevent in debug mode. | 
					
						
							|  |  |  |     # If you are using debugpy and set GEVENT_SUPPORT=True, you can debug with gevent. | 
					
						
							| 
									
										
										
										
											2025-01-03 01:36:23 +08:00
										 |  |  |     if (flask_debug := os.environ.get("FLASK_DEBUG", "0")) and flask_debug.lower() in {"false", "0", "no"}: | 
					
						
							| 
									
										
										
										
											2024-12-31 11:42:51 +08:00
										 |  |  |         from gevent import monkey  # type: ignore | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # gevent | 
					
						
							|  |  |  |         monkey.patch_all() | 
					
						
							| 
									
										
										
										
											2024-12-18 09:05:31 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-31 11:42:51 +08:00
										 |  |  |         from grpc.experimental import gevent as grpc_gevent  # type: ignore | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # grpc gevent | 
					
						
							|  |  |  |         grpc_gevent.init_gevent() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-31 14:45:59 +08:00
										 |  |  |         import psycogreen.gevent  # type: ignore | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         psycogreen.gevent.patch_psycopg() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-31 11:42:51 +08:00
										 |  |  |     from app_factory import create_app | 
					
						
							| 
									
										
										
										
											2024-12-18 09:05:31 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     app = create_app() | 
					
						
							|  |  |  |     celery = app.extensions["celery"] | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-15 12:54:05 +08:00
										 |  |  | if __name__ == "__main__": | 
					
						
							|  |  |  |     app.run(host="0.0.0.0", port=5001) |