我有一个使用 FastAPI 编写的 python Web 应用程序(通过 uvicorn 运行)。在我的应用程序中,我使用的是标准logging模块,该模块使用TimedRotatingFileHandler. 由于我正在登录文件,因此我担心性能。假设我在一个函数中有 3 条日志消息,每次调用端点时都会调用该函数/test。现在想象 1000 个客户端/test同时请求 - 即向日志文件写入 3000 次。
我担心这会影响应用程序的性能,因为 IO 任务非常耗时。我应该使用某种形式的异步日志记录吗?也许打开一个新线程来写入文件?我尝试用谷歌搜索答案,但没有找到标准化的方法。那么它还需要吗?如果是,我应该如何处理这个问题?谢谢!
我正试图在设备和我的服务器之间进行无线电通信.设备中的数据如下所示:
fa-00-01-09-16-aa-00-14-10-01-01-00-01-16-ff-ff-ff-ff-ff-ff-cb-14
Run Code Online (Sandbox Code Playgroud)
最后两个字节是CRC.现在我需要向我的设备发送回复并计算其CRC.设备的数据表没有说太多,它只提供C函数来计算它,但我很难理解我应该为这个函数提供什么
unsigned int CRC_Check(unsigned char *ucCRC_Buf, unsigned char ucBufLength)
{
unsigned int uiX, uiY, uiCRC;
unsigned char ucStart = 0;
uiCRC = 0xFFFF; //set all 1
if (ucBufLength <= 0 || ucStart > ucBufLength)
{
uiCRC = 0;
}
else
{
ucBufLength += ucStart;
for (uiX = (unsigned int)ucStart; uiX < ucBufLength; uiX++)
{
uiCRC = (unsigned int)(uiCRC ^ ucCRC_Buf[uiX]);
for (uiY = 0; uiY <= 7; uiY++)
{
if((uiCRC & 1) != 0)
uiCRC = (unsigned int)((uiCRC …Run Code Online (Sandbox Code Playgroud) 我有一个传感器,它以三个字节输出.我这样看了:
unsigned char byte0,byte1,byte2;
byte0=readRegister(0x25);
byte1=readRegister(0x26);
byte2=readRegister(0x27);
Run Code Online (Sandbox Code Playgroud)
现在我想将这三个字节合并为一个数字:
int value;
value=byte0 + (byte1 << 8) + (byte2 << 16);
Run Code Online (Sandbox Code Playgroud)
它给出了从0到16,777,215的值,但我期望从-8,388,608到8,388,607的值.我虽然int已经通过其实施签署了.即使我尝试定义它signed int value;仍然只给我正数.所以我想我的问题是如何将int转换为它的两个补码?
谢谢!
我有这个代码,它有效,但我不认为我正在以正确的方式做到这一点.我有3个文件main.c,init.c和init.h.
init.h 文件看起来像这样(为简单起见,我在此示例中省略了预处理程序指令):
void init(int param);
int firstCFG(int param);
int secondCFG(int param);
int thirdCFG(int param);
int fourthCFG(int param);
int fifthCFG(int param);
Run Code Online (Sandbox Code Playgroud)
并且init.c文件看起来像这样:
#include "init.h"
void init(int param){
int cfg1 = firstCFG(1);
int cfg2 = secondCFG(2);
int cfg3 = thirdCFG(3);
int cfg4 = fourtCFG(4);
int cfg5 = fifthCFG(5);
}
int firstCFG(int param){
//do stuff
return stuff;
}
int secondCFG(int param){
//do stuff
return stuff;
}
int thirdCFG(int param){
//do stuff
return stuff;
} …Run Code Online (Sandbox Code Playgroud)