aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/reactor.py
Commit message (Collapse)AuthorAgeFilesLines
* klippy: Add Python2 module wrappers and use Python3 module namingKevin O'Connor2021-10-041-1/+1
| | | | | | | Add wrappers for some common Python modules so that the code can run on both Python2 and Python3. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* reactor: Convert to Python3 string encodingKevin O'Connor2021-10-011-2/+2
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* reactor: Record time of recent gc collection sweepsKevin O'Connor2020-09-171-6/+10
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* reactor: Add support for explicit Python garbage collectionKevin O'Connor2020-09-161-14/+36
| | | | | | | Add support for performing Python gc work only from the main reactor thread and only when it appears the main thread is idle. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* reactor: Terminate any greenlets on finalize() callKevin O'Connor2020-09-161-1/+12
| | | | | | | Make sure to terminate any greenlets that are in a pause() state. This is necessary to ensure the reactor can be deallocated. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* reactor: Add explicit finalize() method to clean up reactor stateKevin O'Connor2020-09-161-5/+5
| | | | | | | | | The existence of a __del__() method prevents deallocation on python2 if there are circular references. Replace the __del__() method with a new finalize() call and arrange for it to be called when the main reactor is released. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* reactor: Use "import Queue as queue" for improved Python3 compatibilityKevin O'Connor2020-06-151-3/+3
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* reactor: Support multiple waiting timers on a single completionKevin O'Connor2020-02-191-5/+6
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* reactor: Add support for "completions"Kevin O'Connor2019-07-101-9/+46
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* reactor: Fix some corner cases with self._next_timer handlingKevin O'Connor2019-06-191-16/+21
| | | | | | Make sure to update self._next_timer on greenlet start/stop. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* reactor: Be explicit on which handlers are timer_handler vs file_handlerKevin O'Connor2019-06-091-27/+27
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* reactor: Add support for mutexesKevin O'Connor2019-06-091-1/+33
| | | | | | | Add a mutex object that implements simple queing mutual exclusion for greenlets. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* reactor: support for delayed callbacksJanar Sööt2019-01-071-5/+5
| | | | Signed-off-by: Janar Sööt <janar.soot@gmail.com>
* reactor: Add ability to register callbacksKevin O'Connor2018-06-301-6/+58
| | | | | | | Add the ability to register callbacks - both asynchronous (ie, from another thread) and synchronous. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* reactor: Fix bug causing end() to not always workKevin O'Connor2017-04-131-4/+2
| | | | | | Only set the self._process flag in run() not _dispatch_loop(). Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* reactor: Support pause() command even when the reactor is not runningKevin O'Connor2017-04-011-1/+9
| | | | | | | If the reactor isn't running then implement pause using the system sleep command. This simplifies the users of pause(). Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* reactor: Use the system monotonic clock instead of the normal system clockKevin O'Connor2017-02-061-11/+13
| | | | | | | | | | | | | The normal system clock can have sudden jumps if the system clock is changed. Use the system monotonic clock to avoid these sudden changes in time. It appears the Raspbian OS (which is used by OctoPi) is setup to update the system clock upon network connectivity. This could cause sudden system clock changes which could lead to Klippy processing errors. Using the monotonic clock eliminates these issues. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* reactor: Reload eventtime if a greenlet is reactivatedKevin O'Connor2017-01-101-2/+5
| | | | | | | | Fix a bug causing timers to be delayed when pause() is called from a fd event. The eventtime needs to be reloaded when an old greenlet is reactivated. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* reactor: Add support for greenletsKevin O'Connor2016-11-291-5/+53
| | | | | | | Add support for greenlets - a mechanism for tasks that can pause while still allowing regular reactor events to occur. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* Initial commit of source code.Kevin O'Connor2016-05-251-0/+142
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>