MCPcopy Create free account
hub / github.com/battlecode/battlecode-2018 / poll_thread

Function poll_thread

battlecode-manager/scrimmage.py:119–158  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

117 return t1
118
119def poll_thread():
120 global DB_LOCK
121 global BUSY
122
123 while True:
124 sleep(1)
125 if BUSY:
126 continue
127
128 while DB_LOCK == True:
129 sleep(0.1)
130 DB_LOCK = True
131
132 cur.execute("SELECT (id, red_key, blue_key, map, red_team, blue_team) FROM " + os.environ["TABLE_NAME"] + " WHERE status='queued' or (status='running' and start < (NOW() - INTERVAL '8 min')) ORDER BY start ASC")
133
134 row = cur.fetchone()
135
136 if row is not None:
137 if len(row) == 1:
138 row = row[0][1:-1].split(",")
139 row[0] = int(row[0])
140
141 data = {'id':row[0],'red_key':row[1],'blue_key':row[2],'map':row[3]}
142
143 if not BUSY:
144 BUSY = True
145 print('Running game ' + str(data))
146 cur.execute("UPDATE " + os.environ['TABLE_NAME'] + " SET status='running', start=NOW() WHERE id=%s",(data['id'],))
147 pg.commit()
148
149 try:
150 PROXY_UPLOADER.game_id = row[0]
151 PROXY_UPLOADER.red_id = row[4]
152 PROXY_UPLOADER.blue_id = row[5]
153 except Exception as e:
154 print("error setting team data:", e)
155
156 run_match(data)
157
158 DB_LOCK = False
159
160if __name__ == "__main__":
161 try:

Callers 1

scrimmage.pyFile · 0.85

Calls 1

run_matchFunction · 0.85

Tested by

no test coverage detected