Skip to content

Commit 61fb3ec

Browse files
committed
fix(event-loop): .unref() doesn't work for setInterval timers
We were `.ref()`-ing it every time the timer is re-scheduled, regardless of whether it was unrefed previously or not.
1 parent 81e273e commit 61fb3ec

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/PyEventLoop.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ static PyObject *_enqueueWithDelay(PyObject *_loop, PyEventLoop::AsyncHandle::id
8080

8181
auto handle = PyEventLoop::AsyncHandle::fromId(handleId);
8282
Py_XDECREF(handle->swap(asyncHandle));
83-
handle->addRef();
8483

8584
return asyncHandle;
8685
}
@@ -90,6 +89,8 @@ PyEventLoop::AsyncHandle::id_t PyEventLoop::enqueueWithDelay(PyObject *jobFn, do
9089
if (!_enqueueWithDelay(_loop, handleId, jobFn, delaySeconds, repeat)) {
9190
PyErr_Print(); // RuntimeError: Non-thread-safe operation invoked on an event loop other than the current one
9291
}
92+
auto handle = PyEventLoop::AsyncHandle::fromId(handleId);
93+
handle->addRef();
9394
return handleId;
9495
}
9596

0 commit comments

Comments
 (0)