Skip to content

Commit

Permalink
Fix for FileIO slowing bot performance.This puts the map writing into…
Browse files Browse the repository at this point in the history
… a thread and makes sure it only executes once. (#3100)
  • Loading branch information
ajurna authored and solderzzc committed Aug 8, 2016
1 parent ff380cd commit a5e9131
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import re
import sys
import time
import Queue
import threading

from geopy.geocoders import GoogleV3
from pgoapi import PGoApi
Expand Down Expand Up @@ -69,6 +71,11 @@ def __init__(self, config):
# Make our own copy of the workers for this instance
self.workers = []

# Theading setup for file writing
self.web_update_queue = Queue.Queue(maxsize=1)
self.web_update_thread = threading.Thread(target=self.update_web_location_worker)
self.web_update_thread.start()

def start(self):
self._setup_event_system()
self._setup_logging()
Expand Down Expand Up @@ -976,7 +983,15 @@ def heartbeat(self):
request.get_player()
request.check_awarded_badges()
request.call()
self.update_web_location() # updates every tick
try:
self.web_update_queue.put_nowait(True) # do this outside of thread every tick
except Queue.Full:
pass

def update_web_location_worker(self):
while True:
self.web_update_queue.get()
self.update_web_location()

def get_inventory_count(self, what):
response_dict = self.get_inventory()
Expand Down

1 comment on commit a5e9131

@burnpanck
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would FileIO ever be performance limiting in a program that sleeps most of the time in order not to get immediately flagged by the server due to request flooding? Why not simply reduce sleep a little, or increase walk in the config?

Please sign in to comment.