Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
File renamed without changes.
13 changes: 13 additions & 0 deletions tests/test_uv_timer_when_after_cb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import uvloop
import asyncio


async def main():
loop = asyncio.get_running_loop()
call_ts = loop.time() + 1
timer = loop.call_at(call_ts, lambda: None) # call any function
await asyncio.sleep(1.1)
assert timer.when() == call_ts

uvloop.install()
asyncio.run(main(), debug=True)
4 changes: 2 additions & 2 deletions uvloop/cbhandles.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ cdef class TimerHandle:
self._clear()

cdef inline _clear(self):
if self.timer is None:
if self not in self.loop._timers: # check if timer has already been removed
return

self.callback = None
Expand All @@ -225,7 +225,7 @@ cdef class TimerHandle:
self.loop._timers.remove(self)
finally:
self.timer._close()
self.timer = None # let the UVTimer handle GC
# self.timer = None # let the UVTimer handle GC this will cause a segfault if .when() is called beyond this point

cdef _run(self):
if self._cancelled == 1:
Expand Down