Skip to content

Commit

Permalink
fix threading and session problems
Browse files Browse the repository at this point in the history
  • Loading branch information
doombeaker committed Nov 26, 2024
1 parent 78f3bc1 commit 62537cd
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 46 deletions.
88 changes: 44 additions & 44 deletions src/bizy_server/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,56 +41,56 @@ async def do_get(self, url, params=None, headers=None):
if params:
query_string = urllib.parse.urlencode(params, doseq=True)
url = f"{url}?{query_string}"
session = await self.get_session()
async with session.get(url, headers=headers) as response:
resp_json = await response.json()
if response.status != 200:
return None, ErrorNo(
response.status,
resp_json.get("code", response.status),
None,
resp_json.get("message", await response.text()),
)
return resp_json, None
async with await self.get_session() as session:
async with session.get(url, headers=headers) as response:
resp_json = await response.json()
if response.status != 200:
return None, ErrorNo(
response.status,
resp_json.get("code", response.status),
None,
resp_json.get("message", await response.text()),
)
return resp_json, None

async def do_post(self, url, data=None, headers=None):
session = await self.get_session()
async with session.post(url, json=data, headers=headers) as response:
resp_json = await response.json()
if response.status != 200:
return None, ErrorNo(
response.status,
resp_json.get("code", response.status),
None,
resp_json.get("message", await response.text()),
)
return resp_json, None
async with await self.get_session() as session:
async with session.post(url, json=data, headers=headers) as response:
resp_json = await response.json()
if response.status != 200:
return None, ErrorNo(
response.status,
resp_json.get("code", response.status),
None,
resp_json.get("message", await response.text()),
)
return resp_json, None

async def do_put(self, url, data=None, headers=None):
session = await self.get_session()
async with session.put(url, json=data, headers=headers) as response:
resp_json = await response.json()
if response.status != 200:
return None, ErrorNo(
response.status,
resp_json.get("code", response.status),
None,
resp_json.get("message", await response.text()),
)
return resp_json, None
async with await self.get_session() as session:
async with session.put(url, json=data, headers=headers) as response:
resp_json = await response.json()
if response.status != 200:
return None, ErrorNo(
response.status,
resp_json.get("code", response.status),
None,
resp_json.get("message", await response.text()),
)
return resp_json, None

async def do_delete(self, url, data=None, headers=None):
session = await self.get_session()
async with session.delete(url, json=data, headers=headers) as response:
resp_json = await response.json()
if response.status != 200:
return None, ErrorNo(
response.status,
resp_json.get("code", response.status),
None,
resp_json.get("message", await response.text()),
)
return resp_json, None
async with await self.get_session() as session:
async with session.delete(url, json=data, headers=headers) as response:
resp_json = await response.json()
if response.status != 200:
return None, ErrorNo(
response.status,
resp_json.get("code", response.status),
None,
resp_json.get("message", await response.text()),
)
return resp_json, None

async def user_info(self) -> tuple[dict | None, ErrorNo | None]:
headers, err = self.auth_header()
Expand Down
4 changes: 2 additions & 2 deletions src/bizy_server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ async def commit_bizy_model(request):
# 开启线程检查同步状态
threading.Thread(
target=self.check_sync_status,
args=(self, resp["id"], resp["version_ids"], sid),
args=(resp["id"], resp["version_ids"], sid),
daemon=True,
).start()

Expand Down Expand Up @@ -414,7 +414,7 @@ async def update_model(request):
# 开启线程检查同步状态
threading.Thread(
target=self.check_sync_status,
args=(self, resp["id"], resp["version_ids"]),
args=(resp["id"], resp["version_ids"]),
daemon=True,
).start()

Expand Down

0 comments on commit 62537cd

Please sign in to comment.