Record pathfinding context on flying disconnects
This commit is contained in:
1 parent
0b462f4a76
commit
d4eae5ee5f
5 files changed
+141
-2
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import importlib
|
||||
import functools
|
||||
import threading
|
||||
import time
|
||||
|
||||
from astar import AStar
|
||||
@@ -125,6 +126,43 @@ class Pathfinder(AStar):
|
||||
self.timeout = max(0.0, float(timeout))
|
||||
self.start_time = time.monotonic()
|
||||
|
||||
def astar(self, start, goal, reversePath=False):
|
||||
started_at = time.monotonic()
|
||||
thread = threading.current_thread()
|
||||
thread_id = threading.get_ident()
|
||||
search = {
|
||||
'start': tuple(start),
|
||||
'goal': tuple(goal),
|
||||
'started_at': started_at,
|
||||
'timeout': self.timeout,
|
||||
'thread': thread.name,
|
||||
'thread_id': thread_id,
|
||||
}
|
||||
active = self.g.setdefault('pathfinding_active', {})
|
||||
history = self.g.setdefault('pathfinding_history', [])
|
||||
previous = active.get(thread_id)
|
||||
active[thread_id] = search
|
||||
status = 'error'
|
||||
try:
|
||||
result = super().astar(start, goal, reversePath)
|
||||
status = 'found' if result else 'unreachable'
|
||||
return result
|
||||
except AStarTimeout:
|
||||
status = 'timed out'
|
||||
raise
|
||||
finally:
|
||||
finished_at = time.monotonic()
|
||||
search['finished_at'] = finished_at
|
||||
search['duration'] = finished_at - started_at
|
||||
search['status'] = status
|
||||
history.append(search.copy())
|
||||
del history[:-32]
|
||||
if active.get(thread_id) is search:
|
||||
if previous is None:
|
||||
del active[thread_id]
|
||||
else:
|
||||
active[thread_id] = previous
|
||||
|
||||
@functools.lru_cache(maxsize=BLOCK_CACHE_SIZE)
|
||||
def bair(self, p):
|
||||
state_id = self.chunks.get_block_at(*p)
|
||||
|
||||
Reference in new issue
Block a user