当前位置:网站首页>Multi process pit records (updated from time to time)

Multi process pit records (updated from time to time)

2022-06-21 15:45:00 Dai Meng Ma

1. Deadlocks caused by business logic

This is the most common , But just sort out the logic , This is not easy to happen , But pay attention to : It is best not to define a variable manually , To determine whether a synchronization lock is required .

  • such as : Define a variable needLockFunc or has_lock_func such , Then, to prevent deadlock, judge that the variable is True or False, Where useful in subsequent logic , And then judge the variables , Manually set to... If necessary True, Run out set to False. After the periodic coding , The probability forgets this variable ! Just dig a hole for yourself

2. Subprocess cannot find variable

There are no variables defined in various parent processes in the child process , The subprocess is usually written as a function , Then multiple processes run this function , Many mistakes can be avoided , But there are still some things to be aware of :

  • For example, the user-defined log module is used , But there is no such thing in the subprocess logger, Will result in the use of logger I'm going to report an error , Subprocess cannot continue , But the error is reported in the log module , Therefore, the log module will not write errors to its own records . It's also true that the logs will eventually result , The process did not execute the results

3. Database connection timeout

It was created in the parent process Mysql Connection pool for database , After handing it over to the child process , This connection pool cannot be used when the child process needs to save data after processing , Because the connection of the connection pool is created but not used for a long time Mysql Will actively disconnect this link , If the fruiting process is unlucky, a disconnected connection will be reported Error Code: 2013. Lost connection to MySQL server during query The error of . So it is best to create a connection in the child process when the child process needs to use the database , Don't use the parent process as a baton , The function division is based on the function .

原网站

版权声明
本文为[Dai Meng Ma]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/172/202206211240388523.html