Closed jxu closed 1 year ago
You'll probably need something you monitor every once in a while in your search function. But you need that anyway if you have a way to stop based on timeout. What do you think about something like this?
from concurrent.futures import ThreadPoolExecutor
from threading import Event
import time, itertools
def go_infinite(event):
for i in itertools.count():
if event.is_set():
break
return i
with ThreadPoolExecutor(max_workers=1) as executor:
stop = Event()
future = executor.submit(go_infinite, stop)
while True:
cmd = input('Say stop: ')
print('You said', cmd)
if cmd == 'stop':
stop.set()
break
print('Result:', future.result())
You can also check this: https://superfastpython.com/stop-a-thread-in-python/
Is it documented anywhere? I was thinking about writing an engine myself and wondering how I could implement UCI stateless protocol, including
stop
/go infinite
. I thought I either needed threads or interrupt execution every so often to check if it should stop.But from uci.py I don't see
stop
orgo infinite
implemented anywhere.