Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何避免;“检测到死锁”;博士后问题&x2B;炼金术?_Python_Database_Postgresql_Flask_Sqlalchemy - Fatal编程技术网

Python 如何避免;“检测到死锁”;博士后问题&x2B;炼金术?

Python 如何避免;“检测到死锁”;博士后问题&x2B;炼金术?,python,database,postgresql,flask,sqlalchemy,Python,Database,Postgresql,Flask,Sqlalchemy,以下是我在违规代码行中的代码: webdb.begin(subtransactions=True) (webdb.query(Proxy).filter(Proxy.service_token == service_token)).update( {Proxy.date_deleted_utc: datetime.datetime.utcnow()}, synchronize_session="fetch" ) webdb.commit() 我已尝试启动子事务,并添加了同步的获

以下是我在违规代码行中的代码:

webdb.begin(subtransactions=True)
(webdb.query(Proxy).filter(Proxy.service_token == service_token)).update(
    {Proxy.date_deleted_utc: datetime.datetime.utcnow()},
    synchronize_session="fetch"
)
webdb.commit()
我已尝试启动子事务,并添加了同步的获取

但我仍然得到这个错误:

DBAPIError: (TransactionRollbackError) deadlock detected
DETAIL:  Process 61086 waits for ExclusiveLock on tuple (7217,55) of relation 626383 of database 380717; blocked by process 61094.
Process 61094 waits for ShareLock on transaction 55622134; blocked by process 61088.
Process 61088 waits for ShareLock on transaction 55622141; blocked by process 61086.
HINT:  See server log for query details.
'UPDATE proxies SET date_deleted_utc=%(date_deleted_utc)s WHERE proxies.service_token = %(service_token_1)s' {'date_deleted_utc': datetime.datetime(2015, 7, 2, 12, 57, 23, 2358), 'service_token_1': u'3733a37e-2094-11e5-90b7-0242ac110080'}

我还可以做什么?

通常,通过确保所有流程以相同的顺序获取锁(即更新记录),可以避免死锁。不知道SQLAlchemy是怎么做的,对不起…@NickBarnes:因此子事务。等等,是否有一些外部事务正在进行其他更改?你得把整件事都展示出来。您需要修改至少两条记录以导致死锁,而触发错误消息的记录没有什么特别之处。