Skip to content

Commit 0ceacb6

Browse files
committed
Fixed multithreading error for workers
1 parent fd4ed7f commit 0ceacb6

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

backend/PyMatcha/utils/orm/_model.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
import threading
23
from copy import deepcopy
34
from typing import List
45

@@ -15,7 +16,13 @@ class Model(object):
1516
Base Model class, all other Models will inherit from this
1617
"""
1718

18-
db = connection
19+
_conn = threading.local()
20+
21+
@property
22+
def db(self):
23+
if not hasattr(self._conn, "db"):
24+
self._conn.db = pymysql.connect(**database_config)
25+
return self._conn.db
1926

2027
# Every model should override this with the correct table name
2128
table_name = None

backend/PyMatcha/utils/tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def setup_periodic_tasks(sender, **kwargs):
3030
sender.add_periodic_task(
3131
600, calc_search_min_max.s(), name="Update Minimum and Maximum scores and ages for search every 10 minutes"
3232
)
33-
sender.add_periodic_task(30, random_bot_action.s(), name="200 random bots actions")
33+
# sender.add_periodic_task(30, random_bot_action.s(), name="200 random bots actions")
3434

3535

3636
@celery.task

0 commit comments

Comments
 (0)