CheeseAPI 2.0.6__tar.gz → 2.0.6b2__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.
@@ -334,7 +334,10 @@ class AppProxy:
334
334
  async def get_response(self, request: Request) -> Response:
335
335
  if inspect.isfunction(request.fn):
336
336
  try:
337
- return await request.fn(request = request)
337
+ if 'request' in inspect.signature(request.fn).parameters:
338
+ return await request.fn(request = request)
339
+ else:
340
+ return await request.fn()
338
341
  except Exception as e:
339
342
  self.app.printer.fn_error(e, request)
340
343
  return Response(status = 500)
@@ -1,3 +1,4 @@
1
+ import inspect
1
2
  import datetime, uuid, threading, multiprocessing, asyncio, time, json
2
3
  from typing import Callable, Literal, TYPE_CHECKING
3
4
 
@@ -15,10 +16,10 @@ class Task:
15
16
  for key, value in data.items():
16
17
  if key == '_queue':
17
18
  if value:
18
- value = multiprocessing.Queue()
19
+ value = multiprocessing.get_context('spawn').Queue()
19
20
  value.put(None)
20
21
  else:
21
- value = multiprocessing.Queue()
22
+ value = multiprocessing.get_context('spawn').Queue()
22
23
  elif key == 'first_run_timer':
23
24
  value = datetime.datetime.fromtimestamp(value) if value else None
24
25
  elif key == '_last_run_timer':
@@ -39,7 +40,7 @@ class Task:
39
40
  - expected_run_num: 预期执行次数,若未设置则无限次执行
40
41
  - key: 默认为随机 uuid
41
42
  - run_type: 任务执行方式,可选线程、协程、进程
42
- - args: 默认首位是 `app: CheeseAPI`
43
+ - kwargs: 自动包含 `app: CheeseAPI`,如果不提供 app 参数位置,则不会传入
43
44
  - auto_remove: 任务完成期望次数后是否自动移除
44
45
  - timeout: 当 app.sync_server_url 存在时,任务超过多少秒没有执行完毕则认为执行失败,在 sync_server 中会视为任务删除,None 默认为 interval_time * 2 的值;恢复执行后会在 sync_server 上自动恢复
45
46
  '''
@@ -55,8 +56,8 @@ class Task:
55
56
  self.run_type: Literal['THREAD', 'PROCESS', 'ASYNC'] = run_type
56
57
  ''' 任务执行方式,可选线程、协程、进程 '''
57
58
  self.args: tuple = args
58
- ''' 默认首位是 `app: CheeseAPI` '''
59
59
  self.kwargs: dict = kwargs
60
+ ''' 自动包含 `app: CheeseAPI`,如果不提供 app 参数位置,则不会传入 '''
60
61
  self.auto_remove: bool = auto_remove
61
62
  ''' 任务完成期望次数后是否自动移除 '''
62
63
  self.timeout: float = timeout if timeout is not None else interval_time * 2
@@ -66,7 +67,7 @@ class Task:
66
67
  self._last_run_time: float | None = None
67
68
  self._run_num: int = 0
68
69
  self._handler: threading.Thread | multiprocessing.Process | asyncio.Task | None = None
69
- self._queue = multiprocessing.Queue()
70
+ self._queue = multiprocessing.get_context('spawn').Queue()
70
71
 
71
72
  def __getstate__(self) -> tuple[None, dict[str, any]]:
72
73
  state = {
@@ -146,7 +147,7 @@ class Scheduler:
146
147
  - expected_run_num: 预期执行次数,若未设置则无限次执行
147
148
  - key: 默认为 uuid
148
149
  - run_type: 任务执行方式,可选线程、进程
149
- - args: 默认首位是 `app: CheeseAPI`
150
+ - kwargs: 自动包含 `app: CheeseAPI`,如果不提供 app 参数位置,则不会传入
150
151
  - auto_remove: 任务完成期望次数后是否自动移除
151
152
  - timeout: 当 app.sync_server_url 存在时,任务超过多少秒没有执行完毕则认为执行失败,在 sync_server 中会视为任务删除,None 默认为 interval_time * 2 的值;恢复执行后会在 sync_server 上自动恢复
152
153
  '''
@@ -164,7 +165,7 @@ class Scheduler:
164
165
  - first_run_timer: 首次执行时间,若值小于当前时间则立刻执行
165
166
  - expected_run_num: 预期执行次数,若未设置则无限次执行
166
167
  - key: 默认为 uuid
167
- - args: 默认首位是 `app: CheeseAPI`
168
+ - kwargs: 自动包含 `app: CheeseAPI`,如果不提供 app 参数位置,则不会传入
168
169
  - auto_remove: 任务完成期望次数后是否自动移除
169
170
  - timeout: 当 app.sync_server_url 存在时,任务超过多少秒没有执行完毕则认为执行失败,在 sync_server 中会视为任务删除,None 默认为 interval_time * 2 的值;恢复执行后会在 sync_server 上自动恢复
170
171
  '''
@@ -371,7 +372,10 @@ class SchedulerProxy:
371
372
  now = time.time()
372
373
 
373
374
  try:
374
- fn(self.app, *args, **kwargs)
375
+ if 'app' in inspect.signature(fn).parameters:
376
+ fn(*args, app = self.app, **kwargs)
377
+ else:
378
+ fn(*args, **kwargs)
375
379
  except Exception as e:
376
380
  self.app.printer.scheduler_error(e, task)
377
381
 
@@ -424,7 +428,10 @@ class SchedulerProxy:
424
428
  now = time.time()
425
429
 
426
430
  try:
427
- await fn(self.app, *args, **kwargs)
431
+ if 'app' in inspect.signature(fn).parameters:
432
+ await fn(*args, app = self.app, **kwargs)
433
+ else:
434
+ await fn(*args, **kwargs)
428
435
  except Exception as e:
429
436
  self.app.printer.scheduler_error(e, task)
430
437
 
@@ -210,7 +210,7 @@ class WebsocketProxy:
210
210
  await self.message()
211
211
  await self.disconnect()
212
212
  except Exception as e:
213
- await self.app.printer.websocket_error(self.websocket, e)
213
+ await self.app.printer.websocket_error(e, self.websocket)
214
214
 
215
215
  async def get_response(self) -> Response:
216
216
  headers = {
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: CheeseAPI
3
- Version: 2.0.6
3
+ Version: 2.0.6b2
4
4
  Summary: 一款web协程框架
5
5
  Project-URL: Source, https://github.com/CheeseUnknown/CheeseAPI
6
6
  Author-email: Cheese Unknown <cheese@cheese.ren>
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "CheeseAPI"
7
- version = "2.0.6"
7
+ version = "2.0.6-beta.2"
8
8
  description = "一款web协程框架"
9
9
  readme = "README.md"
10
10
  license-files = { paths = [ "LICENSE" ] }
File without changes
File without changes
File without changes
File without changes
File without changes