简体   繁体   English

sqlalchemy中的并发

[英]Concurrency in sqlalchemy

I'm currently developing an application which connects to a database using sqlalchemy. 我目前正在开发一个使用sqlalchemy连接到数据库的应用程序。 The idea consists of having several instances of the application running in different computers using the same database. 这个想法包括使应用程序的多个实例在使用同一数据库的不同计算机上运行。 I want to be able to see changes in the database in all instances of the application once they are commited. 提交后,我希望能够在应用程序的所有实例中查看数据库中的更改。 I'm currently using sqlalchemy event interface, however it's not working when I have several concurrent instances of the application. 我当前正在使用sqlalchemy事件接口,但是当我有应用程序的多个并发实例时,该接口不起作用。 I change something in one of the instances, but there are no signals emitted in the other instances. 我在其中一个实例中进行了更改,但在其他实例中没有发出信号。

You said it, you are using SQLAlchemy's event interface, it is not the one of the RDBMS, and SQLAlchemy does not communicate with the other instances connected to that DB. 您说的是,您使用的是SQLAlchemy的事件接口,它不是RDBMS的事件接口,并且SQLAlchemy不会与连接到该数据库的其他实例进行通信。

SQLAlchemy's event system calls a function in your own process. SQLAlchemy的事件系统在您自己的进程中调用一个函数。 It's up to you to make this function send a signal to the rest of them via the network (or however they are connected). 使该功能通过网络将信号发送给其余部分(取决于它们的连接),完全取决于您。 As long as SQLAlchemy is concerned, it doesn't know about the other instances connected to your database. 只要涉及到SQLAlchemy,它就不会知道连接到数据库的其他实例。

So, you might want to start another server on the machine with the database running, and make all the other listening to it, and act accordingly. 因此,您可能希望在运行数据库的计算机上启动另一台服务器,并让其他所有服务器监听该服务器,然后采取相应措施。

Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM