From ceb5b4971c244dad9e52ef18240fab6e2feac76a Mon Sep 17 00:00:00 2001 From: Vizonex Date: Sun, 18 Jan 2026 14:23:07 -0600 Subject: [PATCH 1/2] get rid of noop.noop(...) and try eval instead --- winloop/_noop.py | 3 --- winloop/includes/compat.h | 4 ++++ winloop/loop.pxd | 4 +++- winloop/loop.pyx | 35 +++++++++++++---------------------- 4 files changed, 20 insertions(+), 26 deletions(-) delete mode 100644 winloop/_noop.py diff --git a/winloop/_noop.py b/winloop/_noop.py deleted file mode 100644 index bfc14dc..0000000 --- a/winloop/_noop.py +++ /dev/null @@ -1,3 +0,0 @@ -def noop() -> None: - """Empty function to invoke CPython ceval loop.""" - return diff --git a/winloop/includes/compat.h b/winloop/includes/compat.h index 8705e60..d316bc4 100644 --- a/winloop/includes/compat.h +++ b/winloop/includes/compat.h @@ -183,5 +183,9 @@ void PyOS_AfterFork_Child() { // TODO: all versions of _PyEval_EvalFrameDefault so we can get rid of _noop.noop // which would be a massive performance enhancement and allow pyinstaller to compile 3.9 -> 3.14 +// PyObject* PerfomNoop(){ +// PyEval_EvalCode() +// } + #endif // __WINLOOP_COMPAT_H__ \ No newline at end of file diff --git a/winloop/loop.pxd b/winloop/loop.pxd index 131a3de..806b34d 100644 --- a/winloop/loop.pxd +++ b/winloop/loop.pxd @@ -200,7 +200,9 @@ cdef class Loop: cdef _handle_signal(self, sig) cdef _read_from_self(self) - cdef inline int _ceval_process_signals(self) except -1 + # We label _ceval_process_signals as noexcept since we want to try + # and handle exceptions after all signals have been invoked. + cdef inline _ceval_process_signals(self) cdef _invoke_signals(self, bytes data) cdef _set_coroutine_debug(self, bint enabled) diff --git a/winloop/loop.pyx b/winloop/loop.pyx index 0e6d9cf..0b458df 100644 --- a/winloop/loop.pyx +++ b/winloop/loop.pyx @@ -35,21 +35,7 @@ from .includes.python cimport (PY_VERSION_HEX, Context_CopyCurrent, PyOS_BeforeFork, PyUnicode_EncodeFSDefault, PyUnicode_FromString, _Py_RestoreSignals) -# NOTE: Keep if we need to revert at any point in time... -from ._noop import noop - -# NOTE: This has a theoretical chance of hepling to safely bypass the required _noop module... -# The only thing that will need simulations is hitting Ctrl+C on a keyboard which is not easy -# to simulate. For now I'll comment this out we can go back to it in a later winloop 0.2.XX version -# __noop_locals = {} -# exec("def noop(): return", {}, __noop_locals) -# cdef object noop = __noop_locals['noop'] -# # never need __noop_locals again... -# del __noop_locals - - include "includes/stdlib.pxi" - include "errors.pyx" cdef: @@ -456,20 +442,26 @@ cdef class Loop: def __sighandler(self, signum, frame): self._signals.add(signum) - cdef inline int _ceval_process_signals(self) except -1: + cdef inline _ceval_process_signals(self): # Invoke CPython eval loop to let process signals. - if PyErr_CheckSignals() < 0: - return -1 + # Reason for getting rid of noop has more to do with + # pyinstaller and making executable files with winloop + # we can delay exceptions by wrapping in a noexcept so exceptions + # can be handled on a later cycle. + + # All in all a smarter approch was wanted due to pyinstaller but also + # due to needing some more juicy speedups - # Might be gotten rid of soon, since we want to improve evaluation: # SEE: https://github.com/Vizonex/Winloop/issues/58 + PyErr_CheckSignals() # Calling a pure-Python function will invoke # _PyEval_EvalFrameDefault which will process # pending signal callbacks. - if PyObject_CallNoArgs(noop) == NULL: # Might raise ^C - return -1 - return 0 + # this gets rid of needing another module + eval("None") + + cdef _read_from_self(self): cdef bytes sigdata @@ -489,7 +481,6 @@ cdef class Loop: cdef _invoke_signals(self, bytes data): cdef set sigs - self._ceval_process_signals() sigs = self._signals.copy() From fd07515421ccf7a849efdba18d0b52d6fdbe80dd Mon Sep 17 00:00:00 2001 From: Vizonex Date: Sun, 18 Jan 2026 14:25:27 -0600 Subject: [PATCH 2/2] add better explanation for this change. --- winloop/loop.pyx | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/winloop/loop.pyx b/winloop/loop.pyx index 0b458df..1f41d11 100644 --- a/winloop/loop.pyx +++ b/winloop/loop.pyx @@ -446,8 +446,6 @@ cdef class Loop: # Invoke CPython eval loop to let process signals. # Reason for getting rid of noop has more to do with # pyinstaller and making executable files with winloop - # we can delay exceptions by wrapping in a noexcept so exceptions - # can be handled on a later cycle. # All in all a smarter approch was wanted due to pyinstaller but also # due to needing some more juicy speedups @@ -455,10 +453,10 @@ cdef class Loop: # SEE: https://github.com/Vizonex/Winloop/issues/58 PyErr_CheckSignals() - # Calling a pure-Python function will invoke - # _PyEval_EvalFrameDefault which will process - # pending signal callbacks. - # this gets rid of needing another module + + # Calling a pure-Python function (this can also be literally any from) + # will invoke _PyEval_EvalFrameDefault which will process + # pending signal callbacks this attempts to get rid of needing another external module eval("None")