Skip to content

Commit

Permalink
libasynctasks: better handling of exceptions for all threads...
Browse files Browse the repository at this point in the history
  • Loading branch information
cmarshall108 committed Sep 13, 2018
1 parent da3d811 commit 968e19a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
19 changes: 19 additions & 0 deletions src/_threading.pyx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import time

from cpython.exc cimport PyErr_CheckSignals


def thread_wait():
"""
Wait for a short amount of time before executing anymore
code on the thread, this reduces overall idle CPU usage...
"""

# check for Python error signals so we can except
# errors like KeyboardInterrupt, SystemExit etc...
PyErr_CheckSignals()

# hault the current thread for a short amount of time,
# so that we use less CPU usage when idling to free up the
# CPU for other running processes...
time.sleep(0.0001)
17 changes: 2 additions & 15 deletions src/libasynctasks.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ A framework built to make concurrency fast, simple and dynamic;
using the Task concept (and soon to support coroutines async/await...).
"""

from cpython.exc cimport PyErr_CheckSignals

import threading
import time
import collections

include "_threading.pyx"


ctypedef enum TaskResult:
TASK_DONE,
Expand Down Expand Up @@ -503,10 +503,6 @@ cdef class TaskManager(object):
except (KeyboardInterrupt, SystemExit):
break

# check for Python error signals so we can except
# errors like KeyboardInterrupt, SystemExit etc...
PyErr_CheckSignals()

thread_wait()

self.destroy()
Expand All @@ -516,12 +512,3 @@ cdef class TaskManager(object):
self._task_queue = None

super().__del__()


cdef void thread_wait():
"""
Wait for a short amount of time before executing anymore
code on the thread, this reduces overall idle CPU usage...
"""

time.sleep(0.0001)

0 comments on commit 968e19a

Please sign in to comment.