Skip to content

Commit 9ed31e0

Browse files
(api-break) Remove all the thread-related features
1 parent 41dfbcc commit 9ed31e0

File tree

3 files changed

+1
-201
lines changed

3 files changed

+1
-201
lines changed

src/asyncgui_ext/clock.py

Lines changed: 1 addition & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from dataclasses import dataclass
1010
from contextlib import AbstractAsyncContextManager
1111

12-
from asyncgui import Cancelled, Task, move_on_when, _sleep_forever, _current_task
12+
from asyncgui import Task, move_on_when, _sleep_forever, _current_task
1313

1414
TimeUnit = TypeVar("TimeUnit")
1515
ClockCallback: TypeAlias = Callable[[TimeUnit], None]
@@ -383,28 +383,6 @@ async def interpolate_sequence(self, start, end, *, duration, step=0, transition
383383
An alias for :meth:`interpolate_sequence`.
384384
'''
385385

386-
async def run_in_thread(self, func, *, daemon=None, polling_interval) -> Awaitable:
387-
'''
388-
Creates a new thread, runs a function within it, then waits for the completion of that function.
389-
390-
.. code-block::
391-
392-
return_value = await clock.run_in_thread(func, polling_interval=...)
393-
'''
394-
raise NotImplementedError(r"'Clock.run_in_thread()' is not available because 'threading.Thread' is unavailable.")
395-
396-
async def run_in_executor(self, executer, func, *, polling_interval) -> Awaitable:
397-
'''
398-
Runs a function within a :class:`concurrent.futures.ThreadPoolExecutor`, and waits for the completion of the
399-
function.
400-
401-
.. code-block::
402-
403-
executor = ThreadPoolExecutor()
404-
return_value = await clock.run_in_executor(executor, func, polling_interval=...)
405-
'''
406-
raise NotImplementedError(r"'Clock.run_executor()' is not available because 'concurrent.futures.ThreadPoolExecutor' is unavailable.")
407-
408386
def _update(setattr, zip, min, obj, duration, transition, output_seq_type, anim_params, task, p_time, dt):
409387
time = p_time[0] + dt
410388
p_time[0] = time
@@ -509,69 +487,3 @@ def __aenter__(self, _current_task=_current_task) -> Awaitable[Callable[[], Awai
509487

510488
async def __aexit__(self, exc_type, exc_val, exc_tb):
511489
self._event.cancel()
512-
513-
514-
try:
515-
from threading import Thread
516-
except ImportError:
517-
pass
518-
else:
519-
async def run_in_thread(clock: Clock, func, *, daemon=None, polling_interval) -> Awaitable:
520-
return_value = None
521-
exception = None
522-
done = False
523-
524-
def wrapper():
525-
nonlocal return_value, done, exception
526-
try:
527-
return_value = func()
528-
except Exception as e:
529-
exception = e
530-
finally:
531-
done = True
532-
533-
Thread(target=wrapper, daemon=daemon, name="asyncgui_ext.clock.Clock.run_in_thread").start()
534-
async with _repeat_sleeping(clock, polling_interval) as sleep:
535-
while not done:
536-
await sleep()
537-
if exception is not None:
538-
raise exception
539-
return return_value
540-
541-
run_in_thread.__doc__ = Clock.run_in_thread.__doc__
542-
Clock.run_in_thread = run_in_thread
543-
544-
545-
try:
546-
from concurrent.futures import ThreadPoolExecutor
547-
except ImportError:
548-
pass
549-
else:
550-
async def run_in_executor(clock: Clock, executer: ThreadPoolExecutor, func, *, polling_interval) -> Awaitable:
551-
return_value = None
552-
exception = None
553-
done = False
554-
555-
def wrapper():
556-
nonlocal return_value, done, exception
557-
try:
558-
return_value = func()
559-
except Exception as e:
560-
exception = e
561-
finally:
562-
done = True
563-
564-
future = executer.submit(wrapper)
565-
try:
566-
async with _repeat_sleeping(clock, polling_interval) as sleep:
567-
while not done:
568-
await sleep()
569-
except Cancelled:
570-
future.cancel()
571-
raise
572-
if exception is not None:
573-
raise exception
574-
return return_value
575-
576-
run_in_executor.__doc__ = Clock.run_in_executor.__doc__
577-
Clock.run_in_executor = run_in_executor

tests/clock/test_run_in_executor.py

Lines changed: 0 additions & 66 deletions
This file was deleted.

tests/clock/test_run_in_thread.py

Lines changed: 0 additions & 46 deletions
This file was deleted.

0 commit comments

Comments
 (0)