Skip to content

Commit

Permalink
fix(irc): prevent async-tasks to be garbage-collected too early (#144)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
TrueBrain authored Mar 4, 2023
1 parent 5f467f9 commit b7829d6
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion dibridge/irc.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import sys
import time

from openttd_helpers.asyncio_helper import enable_strong_referenced_tasks

from .irc_puppet import IRCPuppet
from . import relay

Expand Down Expand Up @@ -281,7 +283,9 @@ def stop(self):


def start(host, port, name, channel, puppet_ip_range, puppet_postfix, ignore_list, idle_timeout):
asyncio.set_event_loop(asyncio.new_event_loop())
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
enable_strong_referenced_tasks(loop)

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

Expand Down

0 comments on commit b7829d6

Please sign in to comment.