forked from LBRYCommunity/lbry-sdk
[wallet server] take control of executor
This commit is contained in:
parent
9a9d37cc50
commit
662f2bff4c
1 changed files with 4 additions and 2 deletions
|
@ -1,6 +1,7 @@
|
||||||
import signal
|
import signal
|
||||||
import logging
|
import logging
|
||||||
import asyncio
|
import asyncio
|
||||||
|
from concurrent.futures.thread import ThreadPoolExecutor
|
||||||
|
|
||||||
import torba
|
import torba
|
||||||
from torba.server.mempool import MemPool, MemPoolAPI
|
from torba.server.mempool import MemPool, MemPoolAPI
|
||||||
|
@ -116,6 +117,8 @@ class Server:
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
|
executor = ThreadPoolExecutor(1)
|
||||||
|
loop.set_default_executor(executor)
|
||||||
|
|
||||||
def __exit():
|
def __exit():
|
||||||
raise SystemExit()
|
raise SystemExit()
|
||||||
|
@ -123,9 +126,8 @@ class Server:
|
||||||
loop.add_signal_handler(signal.SIGINT, __exit)
|
loop.add_signal_handler(signal.SIGINT, __exit)
|
||||||
loop.add_signal_handler(signal.SIGTERM, __exit)
|
loop.add_signal_handler(signal.SIGTERM, __exit)
|
||||||
loop.run_until_complete(self.start())
|
loop.run_until_complete(self.start())
|
||||||
loop.run_until_complete(self.shutdown_event.wait())
|
|
||||||
except (SystemExit, KeyboardInterrupt):
|
except (SystemExit, KeyboardInterrupt):
|
||||||
pass
|
pass
|
||||||
finally:
|
finally:
|
||||||
|
executor.shutdown(True)
|
||||||
loop.run_until_complete(self.stop())
|
loop.run_until_complete(self.stop())
|
||||||
loop.run_until_complete(loop.shutdown_asyncgens())
|
|
||||||
|
|
Loading…
Reference in a new issue