Skip to content

Commit

Permalink
예상 예외 발생지점 처리 코드 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
oune committed Dec 30, 2022
1 parent e4b19e3 commit 5d9ec22
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 22 deletions.
14 changes: 9 additions & 5 deletions csvwriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ async def file_init(self, path: str):
writer.writerow(self.header)

async def save(self, datas):
path = await self.get_path()
await self.file_init(path)

transpose = [list(x) for x in zip(*datas)]
await save_data(path, transpose)
try:
path = await self.get_path()
await self.file_init(path)

transpose = [list(x) for x in zip(*datas)]
await save_data(path, transpose)
except Exception as e:
print('예외가 발생하였습니다. 전체 로그를 개발자에게 전달 부탁드립니다.')
print(e)
44 changes: 27 additions & 17 deletions realtimeServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ async def read(sensor: Sensor, event_name: str, data_tag_names: list):
await try_read(sensor, event_name, data_tag_names)
except nidaqmx.errors.DaqReadError:
pass
except Exception as e:
print(e)


async def sensor_loop_vib():
Expand All @@ -158,32 +160,40 @@ async def sensor_loop_temp():

@app.get("/{start}/{end}")
async def get_stat_month(start: datetime.date, end: datetime.date):
machine_1_res = await Database(db_1_path).get_by_duration(start, end)
machine_2_res = await Database(db_2_path).get_by_duration(start, end)
try:
machine_1_res = await Database(db_1_path).get_by_duration(start, end)
machine_2_res = await Database(db_2_path).get_by_duration(start, end)

return {'machine_1': machine_1_res,
'machine_2': machine_2_res}
return {'machine_1': machine_1_res, 'machine_2': machine_2_res}
except Exception as e:
print(e)


@app.get("/{date}")
async def get_stat_day(date: datetime.date):
machine_1_res = await Database(db_1_path).get_by_one_day(date)
machine_2_res = await Database(db_2_path).get_by_one_day(date)
try:
machine_1_res = await Database(db_1_path).get_by_one_day(date)
machine_2_res = await Database(db_2_path).get_by_one_day(date)

return {'machine_1': machine_1_res,
'machine_2': machine_2_res}
return {'machine_1': machine_1_res,
'machine_2': machine_2_res}
except Exception as e:
print(e)


if __name__ == "__main__":
sensor_vib, sensor_temp = sensor_load(conf)
socket_app = socketio.ASGIApp(sio, app)
try:
sensor_vib, sensor_temp = sensor_load(conf)
socket_app = socketio.ASGIApp(sio, app)

sensor_task_vib = sio.start_background_task(sensor_loop_vib)
sensor_task_temp = sio.start_background_task(sensor_loop_temp)
sensor_task_vib = sio.start_background_task(sensor_loop_vib)
sensor_task_temp = sio.start_background_task(sensor_loop_temp)

main_loop = asyncio.get_event_loop()
socket_server = server_load(socket_app, conf, main_loop)
main_loop = asyncio.get_event_loop()
socket_server = server_load(socket_app, conf, main_loop)

main_loop.run_until_complete(socket_server.serve())
main_loop.run_until_complete(sensor_task_vib)
main_loop.run_until_complete(sensor_task_temp)
main_loop.run_until_complete(socket_server.serve())
main_loop.run_until_complete(sensor_task_vib)
main_loop.run_until_complete(sensor_task_temp)
except Exception as e:
print(e)

0 comments on commit 5d9ec22

Please sign in to comment.