Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions evolver/evolver.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/local/bin/env python3.6
#!/usr/bin/env python
import yaml
import time
import asyncio
Expand All @@ -22,7 +22,7 @@ def start_background_loop(loop):
evolver_ip = s.getsockname()[0]
s.close()
with open(os.path.realpath(os.path.join(os.getcwd(),os.path.dirname(__file__), CONF_FILENAME)), 'r') as ymlfile:
conf = yaml.load(ymlfile)
conf = yaml.safe_load(ymlfile)

conf['evolver_ip'] = evolver_ip

Expand All @@ -35,18 +35,22 @@ def start_background_loop(loop):

# Set up data broadcasting
bloop = asyncio.new_event_loop()
last_time = None
last_time = 0
running = False
while True:
current_time = time.time()
duration = current_time - last_time

commands_in_queue = evolver_server.get_num_commands() > 0
time_reached = duration > conf['broadcast_timing']

if (last_time is None or current_time - last_time > conf['broadcast_timing'] or commands_in_queue) and not running:
if last_time is None or current_time - last_time > conf['broadcast_timing']:
if (time_reached or commands_in_queue) and not running:
if time_reached:
last_time = current_time
try:
running = True
bloop.run_until_complete(evolver_server.broadcast(commands_in_queue))
running = False
except:
pass
time.sleep(0.1)