使用python在SQLite数据库中重复编写数据

时间:2022-03-13 08:04:17

I want to use SQLite for my GUI Python application but I have to update database every 500 MS without effecting the performance of my program.

我想将SQLite用于我的GUI Python应用程序,但我必须每500 MS更新一次数据库而不影响我的程序的性能。

I'm using PyQt4,So I thought about using QThread but it seems difficult to deal with, so I wondered if it was the best way before really trying to understand it.

我正在使用PyQt4,所以我考虑使用QThread,但似乎很难处理,所以我想知道它是否是真正尝试理解之前的最佳方式。

My Question is: is QThread the best way or there are other ways?‬

我的问题是:QThread是最好的方式还是其他方式?

1 个解决方案

#1


1  

According to the fact that python implementation rely on the GIL, even with using threads or timer you won't be able to do something (potentially costly) in your program without effecting the global performance of the program.

根据python实现依赖于GIL的事实,即使使用线程或计时器,您也无法在程序中执行某些操作(可能代价高昂),而不会影响程序的全局性能。

I will suggest you to have a look to multiprocessing module to get around of this limitation. Using this module, you will no more use threads (that are affected by the GIL), but processes (not affected by GIL).

我建议你看看多处理模块来解决这个限制。使用此模块,您将不再使用线程(受GIL影响),而是使用进程(不受GIL影响)。

Maybe you could create a subprocess that will arm a timer to make the update every 500ms when the main process will continue his job.

也许你可以创建一个子进程,当主进程继续他的工作时,它将设置一个定时器,每500ms进行一次更新。

Then, you will let the system do the job of balancing the programs and it may be better in term of responsiveness (especially in a multi core environment)

然后,您将让系统完成平衡程序的工作,并且在响应性方面可能更好(特别是在多核环境中)

#1


1  

According to the fact that python implementation rely on the GIL, even with using threads or timer you won't be able to do something (potentially costly) in your program without effecting the global performance of the program.

根据python实现依赖于GIL的事实,即使使用线程或计时器,您也无法在程序中执行某些操作(可能代价高昂),而不会影响程序的全局性能。

I will suggest you to have a look to multiprocessing module to get around of this limitation. Using this module, you will no more use threads (that are affected by the GIL), but processes (not affected by GIL).

我建议你看看多处理模块来解决这个限制。使用此模块,您将不再使用线程(受GIL影响),而是使用进程(不受GIL影响)。

Maybe you could create a subprocess that will arm a timer to make the update every 500ms when the main process will continue his job.

也许你可以创建一个子进程,当主进程继续他的工作时,它将设置一个定时器,每500ms进行一次更新。

Then, you will let the system do the job of balancing the programs and it may be better in term of responsiveness (especially in a multi core environment)

然后,您将让系统完成平衡程序的工作,并且在响应性方面可能更好(特别是在多核环境中)