Skip to content

Commit 7b08e0c

Browse files
Guillaume De Saint MartinGuillaumeDSM
authored andcommitted
[BotLoop] run with custom timeout
1 parent 77efdc0 commit 7b08e0c

File tree

6 files changed

+16
-10
lines changed

6 files changed

+16
-10
lines changed

octobot/octobot.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ cdef class OctoBot:
5252
cdef public octobot_channel_consumer.OctoBotChannelGlobalConsumer global_consumer
5353
cdef public configuration_manager.ConfigurationManager configuration_manager
5454

55-
cpdef object run_in_main_asyncio_loop(self, object coroutine, bint log_exceptions=*)
55+
cpdef object run_in_main_asyncio_loop(self, object coroutine, bint log_exceptions=*, object timeout=*)
5656
cpdef void set_watcher(self, object watcher)
5757
cpdef object get_aiohttp_session(self)
5858
cpdef object get_edited_config(self, str config_key, bint dict_only=*)

octobot/octobot.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import aiohttp
2020

2121
import octobot_commons.enums as enums
22+
import octobot_commons.constants as commons_constants
2223
import octobot_commons.logging as logging
2324
import octobot_commons.configuration as configuration
2425
import octobot_commons.signals as signals
@@ -170,8 +171,9 @@ def get_trading_mode(self):
170171
except StopIteration:
171172
return None
172173

173-
def run_in_main_asyncio_loop(self, coroutine, log_exceptions=True):
174-
return self.task_manager.run_in_main_asyncio_loop(coroutine, log_exceptions=log_exceptions)
174+
def run_in_main_asyncio_loop(self, coroutine, log_exceptions=True,
175+
timeout=commons_constants.DEFAULT_FUTURE_TIMEOUT):
176+
return self.task_manager.run_in_main_asyncio_loop(coroutine, log_exceptions=log_exceptions, timeout=timeout)
175177

176178
def set_watcher(self, watcher):
177179
self.task_manager.watcher = watcher

octobot/octobot_api.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ cdef class OctoBotAPI:
3333
cpdef str get_bot_id(self)
3434
cpdef str get_matrix_id(self)
3535
cpdef object get_aiohttp_session(self)
36-
cpdef object run_in_main_asyncio_loop(self, object coroutine, bint log_exceptions=*)
36+
cpdef object run_in_main_asyncio_loop(self, object coroutine, bint log_exceptions=*, object timeout=*)
3737
cpdef void stop_tasks(self)
3838
cpdef void stop_bot(self)
3939
cpdef void update_bot(self)

octobot/octobot_api.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# License along with OctoBot. If not, see <https://www.gnu.org/licenses/>.
1616
import octobot.constants as constants
1717
import octobot.commands as commands
18-
import octobot.community
18+
import octobot_commons.constants as commons_constants
1919

2020

2121
class OctoBotAPI:
@@ -65,8 +65,9 @@ def get_matrix_id(self) -> str:
6565
def get_aiohttp_session(self) -> object:
6666
return self._octobot.get_aiohttp_session()
6767

68-
def run_in_main_asyncio_loop(self, coroutine, log_exceptions=True):
69-
return self._octobot.run_in_main_asyncio_loop(coroutine, log_exceptions=log_exceptions)
68+
def run_in_main_asyncio_loop(self, coroutine, log_exceptions=True,
69+
timeout=commons_constants.DEFAULT_FUTURE_TIMEOUT):
70+
return self._octobot.run_in_main_asyncio_loop(coroutine, log_exceptions=log_exceptions, timeout=timeout)
7071

7172
def run_in_async_executor(self, coroutine):
7273
return self._octobot.task_manager.run_in_async_executor(coroutine)

octobot/task_manager.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ cdef class TaskManager:
3636
cpdef void run_forever(self, object coroutine)
3737
cpdef void create_pool_executor(self, int workers=*)
3838
cpdef void init_async_loop(self)
39-
cpdef object run_in_main_asyncio_loop(self, object coroutine, bint log_exceptions=*)
39+
cpdef object run_in_main_asyncio_loop(self, object coroutine, bint log_exceptions=*, object timeout=*)

octobot/task_manager.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import octobot_commons.asyncio_tools as asyncio_tools
2222
import octobot_commons.logging as logging
23+
import octobot_commons.constants as commons_constants
2324

2425
import octobot.constants as constants
2526

@@ -130,8 +131,10 @@ def _create_new_asyncio_main_loop(self):
130131
name=f"{self.get_name()} new asyncio main loop")
131132
self.current_loop_thread.start()
132133

133-
def run_in_main_asyncio_loop(self, coroutine, log_exceptions=True):
134-
return asyncio_tools.run_coroutine_in_asyncio_loop(coroutine, self.async_loop, log_exceptions=log_exceptions)
134+
def run_in_main_asyncio_loop(self, coroutine, log_exceptions=True,
135+
timeout=commons_constants.DEFAULT_FUTURE_TIMEOUT):
136+
return asyncio_tools.run_coroutine_in_asyncio_loop(coroutine, self.async_loop,
137+
log_exceptions=log_exceptions, timeout=timeout)
135138

136139
def run_in_async_executor(self, coroutine):
137140
if self.executors is not None:

0 commit comments

Comments
 (0)