8000 Removed threaded operation entirely to help travis tests to work. · gitpython-developers/async@665f4f2 · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Apr 14, 2024. It is now read-only.

Commit 665f4f2

Browse files
committed
Removed threaded operation entirely to help travis tests to work.
It's better that way, as it's time to see that async doesn't do what it was meant to do, at least not in multi-threaded mode.
1 parent 9770bb3 commit 665f4f2

File tree

7 files changed

+18
-124
lines changed

7 files changed

+18
-124
lines changed

async/channel.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,16 @@
44
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
55
"""Contains a queue based channel implementation"""
66
try:
7-
from queue import (
8-
Empty,
9-
Full
10-
)
7+
from queue import Empty
118
except ImportError:
12-
from Queue import (
13-
Empty,
14-
Full
15-
)
9+
from Queue import Empty
1610

1711
from .util import (
1812
AsyncQueue,
1913
SyncQueue,
2014
ReadOnly
2115
)
2216

23-
from time import time
2417
import threading
2518
import sys
2619

async/pool.py

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,12 @@
33
# This module is part of async and is released under
44
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
55
"""Implementation of a thread-pool working with channels"""
6-
from .thread import (
7-
WorkerThread,
8-
StopProcessing,
9-
)
6+
from .thread import WorkerThread
107
from threading import Lock
118

12-
from .util import (
13-
AsyncQueue,
14-
DummyLock
15-
)
16-
17-
try:
18-
from queue import (
19-
Queue,
20-
Empty
21-
)
22-
except ImportError:
23-
from Queue import (
24-
Queue,
25-
Empty
26-
)
27-
9+
from .util import AsyncQueue
2810
from .graph import Graph
2911
from .channel import (
30-
mkchannel,
3112
ChannelWriter,
3213
Channel,
3314
SerialChannel,
@@ -357,8 +338,8 @@ def set_size(self, size=0):
357338
assert size > -1, "Size cannot be negative"
358339

359340
# Enforce sync operation in py3 - it doesn't work. More information in-code at async.test.lib.py:9
360-
if sys.version_info.major > 2:
361-
log.debug("py3 compatibility issue: async doesn't work reliably in async mode - enforcing synchronous operation")
341+
if True:
342+
log.debug("async: Actual asynchronous operation was disabled as it is slower that way")
362343
size = 0
363344
# end
364345

async/test/test_example.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
# This module is part of async and is released under
44
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
5 9E81 5
"""Module containing examples from the documentaiton"""
6-
from .lib import (
7-
TestBase,
8-
py2
9-
)
6+
from .lib import TestBase
107

118
from async.pool import ThreadPool
129
from async.task import (
@@ -24,11 +21,6 @@ def test_usage(self):
2421
# default size is 0, synchronous mode
2522
assert p.size() == 0
2623

27-
# now tasks would be processed asynchronously
28-
p.set_size(1)
29-
if py2:
30-
assert p.size() == 1
31-
3224
# A task performing processing on items from an iterator
3325
t = IteratorThreadTask(iter(list(range(10))), "power", lambda i: i*i)
3426
reader = p.add_task(t)

async/test/test_pool.py

Lines changed: 1 addition & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
from async.thread import terminate_threads
2323
from async.util import cpu_count
2424

25-
import threading
2625
import time
2726
import sys
2827

@@ -381,38 +380,10 @@ def _assert_async_dependent_tasks(self, pool):
381380

382381
@terminate_threads
383382
def test_base(self):
384-
max_wait_attempts = 3
385-
sleep_time = 0.1
386-
for mc in range(max_wait_attempts):
387-
# wait for threads to die
388-
if len(threading.enumerate()) != 1:
389-
time.sleep(sleep_time)
390-
# END for each attempt
391-
assert len(threading.enumerate()) == 1, "Waited %f s for threads to die, its still alive" % (max_wait_attempts, sleep_time)
392-
393383
p = ThreadPool()
394384

395-
# default pools have no workers
396-
assert p.size() == 0
397-
398-
# increase and decrease the size
399-
num_threads = len(threading.enumerate())
400-
for i in range(self.max_threads):
401-
p.set_size(i)
402-
if py2:
403-
assert p.size() == i
404-
assert len(threading.enumerate()) == num_threads + i
405-
406-
for i in range(self.max_threads, -1, -1):
407-
p.set_size(i)
408-
if py2:
409-
assert p.size() == i
410-
385+
# default pools have no workers - and threading was removed entirely ...
411386
assert p.size() == 0
412-
# threads should be killed already, but we let them a tiny amount of time
413-
# just to be sure
414-
time.sleep(0.05)
415-
assert len(threading.enumerate()) == num_threads
416387

417388
# SINGLE TASK SERIAL SYNC MODE
418389
##############################
@@ -454,45 +425,3 @@ def test_base(self):
454425
# DEPENDENT TASKS SYNC MODE
455426
###########################
456427
self._assert_async_dependent_tasks(p)
457-
458-
459-
# SINGLE TASK THREADED ASYNC MODE ( 1 thread )
460-
##############################################
461-
# step one gear up - just one thread for now.
462-
p.set_size(1)
463-
if py2:
464-
assert p.size() == 1
465-
assert len(threading.enumerate()) == num_threads + 1
466-
# deleting the pool stops its threads - just to be sure ;)
467-
# Its not synchronized, hence we wait a moment
468-
del(p)
469-
time.sleep(0.05)
470-
if py2:
471-
assert len(threading.enumerate()) == num_threads
472-
473-
p = ThreadPool(1)
474-
if py2:
475-
assert len(threading.enumerate()) == num_threads + 1
476-
477-
# here we go
478-
self._assert_single_task(p, True)
479-
480-
481-
482-
# SINGLE TASK ASYNC MODE ( 2 threads )
483-
######################################
484-
# two threads to compete for a single task
485-
p.set_size(2)
486-
self._assert_single_task(p, True)
487-
488-
# real stress test- should be native on every dual-core cpu with 2 hardware
489-
# threads per core
490-
p.set_size(4)
491-
self._assert_single_task(p, True)
492-
493-
494-
# DEPENDENT TASK ASYNC MODE
495-
###########################
496-
self._assert_async_dependent_tasks(p)
497-
498-
sys.stderr.write("Done with everything\n")

async/test/test_thread.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@
1010
terminate_threads
1111
)
1212

13-
try:
14-
from queue import Queue
15-
except ImportError:
16-
from Queue import Queue
17-
1813
import sys
1914
import time
2015

async/thread.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,14 +177,13 @@ def run(self):
177177

178178
try:
179179
try:
180-
rval = None
181180
if inspect.ismethod(routine):
182181
if routine.__self__ is None:
183-
rval = routine(self, arg)
182+
routine(self, arg)
184183
else:
185-
rval = routine(arg)
184+
routine(arg)
186185
elif inspect.isroutine(routine):
187-
rval = routine(arg)
186+
routine(arg)
188187
else:
189188
# ignore unknown items
190189
log.warn("%s: task %s was not understood - terminating", self.getName(), str(tasktuple))
@@ -199,8 +198,8 @@ def run(self):
199198
except StopProcessing:
200199
break
201200
except Exception as e:
202-
log.error("%s: Task %s raised unhandled exception: %s - this really shouldn't happen !",
203-
(self.getName(), str(tasktuple), str(e)))
201+
log.error("%s: Task raised unhandled exception: %s - this really shouldn't happen !",
202+
(self.getName(), str(e)))
204203
continue # just continue
205204
# END routine exception handling
206205

doc/source/changes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
#########
22
Changelog
33
#########
4+
*****
5+
0.6.2
6+
*****
7+
* Added python 3.X compatibility. As it doesn't work deterministically in this version, it shouldn't be used in production !
8+
49
*****
510
0.6.1
611
*****

0 commit comments

Comments
 (0)
0