Skip to content

Commit b7829d6

Browse files
authored
fix(irc): prevent async-tasks to be garbage-collected too early (#144)
Python only keeps a weak-reference to tasks created, so when the GC comes by, it can remove tasks that are not assigned to a variable. The async-helper changes the factory to always store a strong reference, avoiding this issue.
1 parent 5f467f9 commit b7829d6

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

dibridge/irc.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import sys
88
import time
99

10+
from openttd_helpers.asyncio_helper import enable_strong_referenced_tasks
11+
1012
from .irc_puppet import IRCPuppet
1113
from . import relay
1214

@@ -281,7 +283,9 @@ def stop(self):
281283

282284

283285
def start(host, port, name, channel, puppet_ip_range, puppet_postfix, ignore_list, idle_timeout):
284-
asyncio.set_event_loop(asyncio.new_event_loop())
286+
loop = asyncio.new_event_loop()
287+
asyncio.set_event_loop(loop)
288+
enable_strong_referenced_tasks(loop)
285289

286290
relay.IRC = IRCRelay(host, port, name, channel, puppet_ip_range, puppet_postfix, ignore_list, idle_timeout)
287291

0 commit comments

Comments
 (0)