Skip to content
This repository was archived by the owner on Feb 12, 2022. It is now read-only.

Commit 50d418d

Browse files
committed
Close a file descriptor for dictionaries as they are read
1 parent 7d5f95f commit 50d418d

File tree

2 files changed

+5
-30
lines changed

2 files changed

+5
-30
lines changed

server/__init__.py

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -60,27 +60,6 @@ def prune():
6060
delete_room(key)
6161
del rooms
6262
gc.collect()
63-
return
64-
# if len(stale) > 0:
65-
# cur_path = os.path.dirname(os.path.abspath(__file__))
66-
# # add playtimes to master playtimes list
67-
# with open(os.path.join(cur_path, 'all-playtimes.txt'), 'a+') as f:
68-
# playtimes = [json.dumps([v['date_created'], v['playtime']])
69-
# for v in sorted(stale, key=lambda k: k.get('date_modified'))
70-
# if v['playtime'] > 10]
71-
# f.write("\r\n".join(playtimes))
72-
# del playtimes
73-
# # add custom words to master list
74-
# with open(os.path.join(cur_path, 'all-custom-words.txt'), 'a+') as f:
75-
# custom_words = [json.dumps(v['options']['custom'])
76-
# for v in stale if v['options']['custom'] is not False]
77-
# f.write("\r\n".join(custom_words))
78-
# del custom_words
79-
# # prune master rooms list
80-
# for game in stale:
81-
# del ROOMS[game.get('game_id')]
82-
# del stale
83-
# gc.collect()
8463

8564
@app.route('/debug-sentry')
8665
def trigger_error():
@@ -158,10 +137,8 @@ def on_leave(data):
158137
@socketio.on('flip_card')
159138
def on_flip_card(data):
160139
"""flip card and rebroadcast game object"""
161-
room = data['room']
162-
card = data['card']
163-
ROOMS[room].flip_card(card)
164-
send(ROOMS[room].to_json(), room=room)
140+
ROOMS[data['room']].flip_card(data['card'])
141+
send(ROOMS[data['room']].to_json(), room=data['room'])
165142

166143
@socketio.on('regenerate')
167144
def on_regenerate(data):

server/codenames/game.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,8 @@ def playtime(self):
116116
# Convert to Unix timestamp
117117
d1_ts = time.mktime(d1.timetuple())
118118
d2_ts = time.mktime(d2.timetuple())
119-
120119
return round(float(d2_ts-d1_ts) / 60, 2)
121120

122-
123121
def __get_words(self, size):
124122
"""Generate a list of words"""
125123
if not self.dictionary in DICTIONARIES.keys():
@@ -143,9 +141,9 @@ def __get_words(self, size):
143141
final_words = words[0:BOARD_SIZE[size]]
144142
return final_words
145143

146-
def __load_words(self, dict):
147-
words_file = open(DICTIONARIES.get(dict), 'r')
148-
return [elem for elem in words_file.read().split('\n') if len(elem.strip()) > 0]
144+
def __load_words(self, d):
145+
with open(DICTIONARIES.get(d), 'r') as words_file:
146+
return [elem for elem in words_file.read().split('\n') if len(elem.strip()) > 0]
149147

150148
def __get_layout(self, size, teams):
151149
"""Randomly generate a card layout"""

0 commit comments

Comments
 (0)