CheeseAPI 0.3.8__tar.gz → 0.3.10__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {cheeseapi-0.3.8 → cheeseapi-0.3.10}/CheeseAPI/app.py +24 -33
- {cheeseapi-0.3.8 → cheeseapi-0.3.10}/CheeseAPI/handle.py +44 -35
- {cheeseapi-0.3.8 → cheeseapi-0.3.10}/CheeseAPI/signal.py +0 -1
- {cheeseapi-0.3.8 → cheeseapi-0.3.10}/PKG-INFO +3 -7
- {cheeseapi-0.3.8 → cheeseapi-0.3.10}/README.md +2 -6
- {cheeseapi-0.3.8 → cheeseapi-0.3.10}/pyproject.toml +1 -1
- {cheeseapi-0.3.8 → cheeseapi-0.3.10}/.gitignore +0 -0
- {cheeseapi-0.3.8 → cheeseapi-0.3.10}/CheeseAPI/__init__.py +0 -0
- {cheeseapi-0.3.8 → cheeseapi-0.3.10}/CheeseAPI/cors.py +0 -0
- {cheeseapi-0.3.8 → cheeseapi-0.3.10}/CheeseAPI/exception.py +0 -0
- {cheeseapi-0.3.8 → cheeseapi-0.3.10}/CheeseAPI/file.py +0 -0
- {cheeseapi-0.3.8 → cheeseapi-0.3.10}/CheeseAPI/module.py +0 -0
- {cheeseapi-0.3.8 → cheeseapi-0.3.10}/CheeseAPI/protocol.py +0 -0
- {cheeseapi-0.3.8 → cheeseapi-0.3.10}/CheeseAPI/request.py +0 -0
- {cheeseapi-0.3.8 → cheeseapi-0.3.10}/CheeseAPI/response.py +0 -0
- {cheeseapi-0.3.8 → cheeseapi-0.3.10}/CheeseAPI/route.py +0 -0
- {cheeseapi-0.3.8 → cheeseapi-0.3.10}/CheeseAPI/server.py +0 -0
- {cheeseapi-0.3.8 → cheeseapi-0.3.10}/CheeseAPI/websocket.py +0 -0
- {cheeseapi-0.3.8 → cheeseapi-0.3.10}/CheeseAPI/worker.py +0 -0
- {cheeseapi-0.3.8 → cheeseapi-0.3.10}/CheeseAPI/workspace.py +0 -0
- {cheeseapi-0.3.8 → cheeseapi-0.3.10}/LICENSE +0 -0
|
@@ -39,43 +39,34 @@ class App:
|
|
|
39
39
|
'startedWorkerNum': multiprocessing.Value('i', 0)
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
def
|
|
42
|
+
def run(self, *, managers: Dict[str, Any] = {}):
|
|
43
43
|
try:
|
|
44
|
-
self.
|
|
44
|
+
self.managers.update(managers)
|
|
45
|
+
manager = multiprocessing.Manager()
|
|
46
|
+
self._managers['workspace.logger'] = manager.Value(str, self.workspace.logger)
|
|
47
|
+
|
|
48
|
+
self._handle._server_beforeStartingHandle(self)
|
|
49
|
+
if signal.receiver('server_beforeStartingHandle'):
|
|
50
|
+
signal.send('server_beforeStartingHandle')
|
|
51
|
+
|
|
52
|
+
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
53
|
+
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
|
54
|
+
sock.bind((self.server.host, self.server.port))
|
|
55
|
+
sock.listen(self.server.backlog)
|
|
56
|
+
sock.set_inheritable(True)
|
|
57
|
+
|
|
58
|
+
multiprocessing.allow_connection_pickling()
|
|
59
|
+
for i in range(0, self.server.workers - 1):
|
|
60
|
+
process = multiprocessing.Process(target = run, args = (self, sock), name = f'CheeseAPI_subprocess')
|
|
61
|
+
process.start()
|
|
62
|
+
|
|
63
|
+
run(self, sock, True)
|
|
64
|
+
|
|
65
|
+
while self._managers['startedWorkerNum'].value != 0:
|
|
66
|
+
time.sleep(0.01)
|
|
45
67
|
except Exception as e:
|
|
46
68
|
sys.excepthook(Exception, e, sys.exc_info()[2])
|
|
47
69
|
|
|
48
|
-
def run(self, *, managers: Dict[str, Any] = {}):
|
|
49
|
-
if 'startTimer' not in app.g:
|
|
50
|
-
logger.error('The app has not yet been initiated')
|
|
51
|
-
else:
|
|
52
|
-
try:
|
|
53
|
-
self.managers.update(managers)
|
|
54
|
-
manager = multiprocessing.Manager()
|
|
55
|
-
self._managers['workspace.logger'] = manager.Value(str, self.workspace.logger)
|
|
56
|
-
|
|
57
|
-
self._handle._server_beforeStartingHandle(self)
|
|
58
|
-
if signal.receiver('server_beforeStartingHandle'):
|
|
59
|
-
signal.send('server_beforeStartingHandle')
|
|
60
|
-
|
|
61
|
-
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
62
|
-
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
|
63
|
-
sock.bind((self.server.host, self.server.port))
|
|
64
|
-
sock.listen(self.server.backlog)
|
|
65
|
-
sock.set_inheritable(True)
|
|
66
|
-
|
|
67
|
-
multiprocessing.allow_connection_pickling()
|
|
68
|
-
for i in range(0, self.server.workers - 1):
|
|
69
|
-
process = multiprocessing.Process(target = run, args = (self, sock), name = f'CheeseAPI_subprocess')
|
|
70
|
-
process.start()
|
|
71
|
-
|
|
72
|
-
run(self, sock, True)
|
|
73
|
-
|
|
74
|
-
while self._managers['startedWorkerNum'].value != 0:
|
|
75
|
-
time.sleep(0.01)
|
|
76
|
-
except Exception as e:
|
|
77
|
-
sys.excepthook(Exception, e, sys.exc_info()[2])
|
|
78
|
-
|
|
79
70
|
if signal.receiver('server_beforeStoppingHandle'):
|
|
80
71
|
signal.send('server_beforeStoppingHandle')
|
|
81
72
|
self._handle._server_beforeStoppingHandle(self)
|
|
@@ -2,7 +2,7 @@ import os, time, http, traceback, asyncio
|
|
|
2
2
|
from typing import TYPE_CHECKING, Callable, Tuple, Dict, Any
|
|
3
3
|
|
|
4
4
|
import websockets
|
|
5
|
-
from CheeseLog import logger
|
|
5
|
+
from CheeseLog import logger, ProgressBar
|
|
6
6
|
from websockets.legacy.server import HTTPResponse
|
|
7
7
|
|
|
8
8
|
from CheeseAPI.response import FileResponse, BaseResponse, Response
|
|
@@ -53,38 +53,9 @@ class Handle:
|
|
|
53
53
|
def _exitSignalHandle(self, server):
|
|
54
54
|
server.close()
|
|
55
55
|
|
|
56
|
-
def
|
|
56
|
+
def _server_beforeStartingHandle(self, app: 'App'):
|
|
57
57
|
app.g['startTimer'] = time.time()
|
|
58
58
|
|
|
59
|
-
moduleNum = len(app.modules)
|
|
60
|
-
if moduleNum:
|
|
61
|
-
for i in range(moduleNum):
|
|
62
|
-
Module(app.modules[i])
|
|
63
|
-
|
|
64
|
-
if app.localModules is True:
|
|
65
|
-
localModule = []
|
|
66
|
-
for foldername in os.listdir(app.workspace.base):
|
|
67
|
-
if foldername[0] == '.' or foldername == '__pycache__':
|
|
68
|
-
continue
|
|
69
|
-
folderPath = os.path.join(app.workspace.base, foldername)
|
|
70
|
-
if os.path.isdir(folderPath):
|
|
71
|
-
if (not app.workspace.static or not os.path.exists(os.path.join(app.workspace.base, app.workspace.static)) or not os.path.samefile(folderPath, os.path.join(app.workspace.base, app.workspace.static))) and (not app.workspace.log or not os.path.exists(os.path.join(app.workspace.base, app.workspace.log)) or not os.path.samefile(folderPath, os.path.join(app.workspace.base, app.workspace.log))) and foldername not in app.exclude_localModules:
|
|
72
|
-
localModule.append(foldername)
|
|
73
|
-
app.localModules = localModule
|
|
74
|
-
else:
|
|
75
|
-
app.preferred_localModules = []
|
|
76
|
-
localModuleNum = len(app.localModules)
|
|
77
|
-
if localModuleNum:
|
|
78
|
-
for module in app.preferred_localModules:
|
|
79
|
-
LocalModule(app.workspace.base, module)
|
|
80
|
-
for module in app.localModules:
|
|
81
|
-
if module not in app.preferred_localModules:
|
|
82
|
-
LocalModule(app.workspace.base, module)
|
|
83
|
-
|
|
84
|
-
if signal.receiver('afterInitHandle'):
|
|
85
|
-
signal.send('afterInitHandle')
|
|
86
|
-
|
|
87
|
-
def _server_beforeStartingHandle(self, app: 'App'):
|
|
88
59
|
logger.starting(f'The master process {os.getpid()} started', f'The master process <blue>{os.getpid()}</blue> started')
|
|
89
60
|
|
|
90
61
|
logger.starting(f'''Workspace information:
|
|
@@ -109,13 +80,51 @@ Port: <blue>{app.server.port}</blue>
|
|
|
109
80
|
Workers: <blue>{app.server.workers}</blue>''' + (f'''
|
|
110
81
|
Static: <cyan>{app.server.static}</cyan>''' if app.server.static else ''))
|
|
111
82
|
|
|
112
|
-
|
|
83
|
+
moduleNum = len(app.modules)
|
|
84
|
+
if moduleNum:
|
|
85
|
+
progressBar = ProgressBar()
|
|
86
|
+
message, styledMessage = progressBar(0)
|
|
87
|
+
logger.loading(message, styledMessage, refreshed = False)
|
|
88
|
+
for i in range(moduleNum):
|
|
89
|
+
Module(app.modules[i])
|
|
90
|
+
message, styledMessage = progressBar((i + 1) / moduleNum)
|
|
91
|
+
logger.loading('Modules: ' + message + ' ' + app.modules[i], 'Modules: ' + styledMessage + ' ' + app.modules[i])
|
|
92
|
+
|
|
113
93
|
logger.loaded(f'''Modules:
|
|
114
|
-
''' + ' | '.join(app.modules))
|
|
94
|
+
''' + ' | '.join(app.modules), refreshed = True)
|
|
95
|
+
|
|
96
|
+
if app.localModules is True:
|
|
97
|
+
localModule = []
|
|
98
|
+
for foldername in os.listdir(app.workspace.base):
|
|
99
|
+
if foldername[0] == '.' or foldername == '__pycache__':
|
|
100
|
+
continue
|
|
101
|
+
folderPath = os.path.join(app.workspace.base, foldername)
|
|
102
|
+
if os.path.isdir(folderPath):
|
|
103
|
+
if (not app.workspace.static or not os.path.exists(os.path.join(app.workspace.base, app.workspace.static)) or not os.path.samefile(folderPath, os.path.join(app.workspace.base, app.workspace.static))) and (not app.workspace.log or not os.path.exists(os.path.join(app.workspace.base, app.workspace.log)) or not os.path.samefile(folderPath, os.path.join(app.workspace.base, app.workspace.log))) and foldername not in app.exclude_localModules:
|
|
104
|
+
localModule.append(foldername)
|
|
105
|
+
app.localModules = localModule
|
|
106
|
+
else:
|
|
107
|
+
app.preferred_localModules = []
|
|
108
|
+
localModuleNum = len(app.localModules)
|
|
109
|
+
if localModuleNum:
|
|
110
|
+
progressBar = ProgressBar()
|
|
111
|
+
i = 0
|
|
112
|
+
message, styledMessage = progressBar(i / localModuleNum)
|
|
113
|
+
logger.loading(message, styledMessage, refreshed = False)
|
|
114
|
+
for module in app.preferred_localModules:
|
|
115
|
+
LocalModule(app.workspace.base, module)
|
|
116
|
+
i += 1
|
|
117
|
+
message, styledMessage = progressBar(i / localModuleNum)
|
|
118
|
+
logger.loading('Local Modules: ' + message + ' ' + module, 'Local Modules: ' + styledMessage + ' ' + module)
|
|
119
|
+
for module in app.localModules:
|
|
120
|
+
if module not in app.preferred_localModules:
|
|
121
|
+
LocalModule(app.workspace.base, module)
|
|
122
|
+
i += 1
|
|
123
|
+
message, styledMessage = progressBar(i / localModuleNum)
|
|
124
|
+
logger.loading('Local Modules: ' + message + ' ' + module, 'Local Modules: ' + styledMessage + ' ' + module)
|
|
115
125
|
|
|
116
|
-
if app.localModules:
|
|
117
126
|
logger.loaded(f'''Local Modules:
|
|
118
|
-
''' + ' | '.join(app.localModules))
|
|
127
|
+
''' + ' | '.join(app.localModules), refreshed = True)
|
|
119
128
|
|
|
120
129
|
def _worker_beforeStartingHandle(self):
|
|
121
130
|
logger.debug(f'The subprocess {os.getpid()} started', f'The subprocess <blue>{os.getpid()}</blue> started')
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: CheeseAPI
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.10
|
|
4
4
|
Summary: 一款web协程框架。
|
|
5
5
|
Project-URL: Source, https://github.com/CheeseUnknown/CheeseAPI
|
|
6
6
|
Author-email: Cheese Unknown <cheese@cheese.ren>
|
|
@@ -56,10 +56,7 @@ from CheeseAPI import app, Response
|
|
|
56
56
|
async def test(**kwargs):
|
|
57
57
|
return Response('您好,这里是CheeseAPI!')
|
|
58
58
|
|
|
59
|
-
app.
|
|
60
|
-
|
|
61
|
-
if __name__ == '__main__':
|
|
62
|
-
app.run() # 默认的启动地址:'0.0.0.0',默认的启动端口:5214
|
|
59
|
+
app.run() # 默认的启动地址:0.0.0.0,默认的启动端口:5214
|
|
63
60
|
```
|
|
64
61
|
|
|
65
62
|
运行`app.py`,可以看到打印了一些基础信息,当当前代码的最后一行启动时,代表系统已经可以访问:
|
|
@@ -80,8 +77,6 @@ $ python app.py
|
|
|
80
77
|
(STARTING) 2023-08-24 12:20:56.939158 > The server started on http://0.0.0.0:5214
|
|
81
78
|
```
|
|
82
79
|
|
|
83
|
-
请不要在尚未完全启动时关闭服务器,这可能导致部分进程无法被销毁。
|
|
84
|
-
|
|
85
80
|
使用`ctrl + c`或`kill <pid>`杀死进程,会打印完剩下的内容:
|
|
86
81
|
|
|
87
82
|
```bash
|
|
@@ -115,6 +110,7 @@ CheeseAPI采用类Django的结构:
|
|
|
115
110
|
| model.py | 模型类 |
|
|
116
111
|
| api.py | api接口 |
|
|
117
112
|
| service.py | 业务逻辑实现 |
|
|
113
|
+
| model.py | ORM |
|
|
118
114
|
| handle.py | 初始化逻辑 |
|
|
119
115
|
|
|
120
116
|
## **更多...**
|
|
@@ -39,10 +39,7 @@ from CheeseAPI import app, Response
|
|
|
39
39
|
async def test(**kwargs):
|
|
40
40
|
return Response('您好,这里是CheeseAPI!')
|
|
41
41
|
|
|
42
|
-
app.
|
|
43
|
-
|
|
44
|
-
if __name__ == '__main__':
|
|
45
|
-
app.run() # 默认的启动地址:'0.0.0.0',默认的启动端口:5214
|
|
42
|
+
app.run() # 默认的启动地址:0.0.0.0,默认的启动端口:5214
|
|
46
43
|
```
|
|
47
44
|
|
|
48
45
|
运行`app.py`,可以看到打印了一些基础信息,当当前代码的最后一行启动时,代表系统已经可以访问:
|
|
@@ -63,8 +60,6 @@ $ python app.py
|
|
|
63
60
|
(STARTING) 2023-08-24 12:20:56.939158 > The server started on http://0.0.0.0:5214
|
|
64
61
|
```
|
|
65
62
|
|
|
66
|
-
请不要在尚未完全启动时关闭服务器,这可能导致部分进程无法被销毁。
|
|
67
|
-
|
|
68
63
|
使用`ctrl + c`或`kill <pid>`杀死进程,会打印完剩下的内容:
|
|
69
64
|
|
|
70
65
|
```bash
|
|
@@ -98,6 +93,7 @@ CheeseAPI采用类Django的结构:
|
|
|
98
93
|
| model.py | 模型类 |
|
|
99
94
|
| api.py | api接口 |
|
|
100
95
|
| service.py | 业务逻辑实现 |
|
|
96
|
+
| model.py | ORM |
|
|
101
97
|
| handle.py | 初始化逻辑 |
|
|
102
98
|
|
|
103
99
|
## **更多...**
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|