Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Apr 14, 2024. It is now read-only.

Commit665f4f2

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 whatit was meant to do, at least not in multi-threaded mode.
1 parent9770bb3 commit665f4f2

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-
fromqueueimport (
8-
Empty,
9-
Full
10-
)
7+
fromqueueimportEmpty
118
exceptImportError:
12-
fromQueueimport (
13-
Empty,
14-
Full
15-
)
9+
fromQueueimportEmpty
1610

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

23-
fromtimeimporttime
2417
importthreading
2518
importsys
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 .threadimport (
7-
WorkerThread,
8-
StopProcessing,
9-
)
6+
from .threadimportWorkerThread
107
fromthreadingimportLock
118

12-
from .utilimport (
13-
AsyncQueue,
14-
DummyLock
15-
)
16-
17-
try:
18-
fromqueueimport (
19-
Queue,
20-
Empty
21-
)
22-
exceptImportError:
23-
fromQueueimport (
24-
Queue,
25-
Empty
26-
)
27-
9+
from .utilimportAsyncQueue
2810
from .graphimportGraph
2911
from .channelimport (
30-
mkchannel,
3112
ChannelWriter,
3213
Channel,
3314
SerialChannel,
@@ -357,8 +338,8 @@ def set_size(self, size=0):
357338
assertsize>-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-
ifsys.version_info.major>2:
361-
log.debug("py3 compatibility issue: async doesn't work reliably in async mode - enforcing synchronous operation")
341+
ifTrue:
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
55
"""Module containing examples from the documentaiton"""
6-
from .libimport (
7-
TestBase,
8-
py2
9-
)
6+
from .libimportTestBase
107

118
fromasync.poolimportThreadPool
129
fromasync.taskimport (
@@ -24,11 +21,6 @@ def test_usage(self):
2421
# default size is 0, synchronous mode
2522
assertp.size()==0
2623

27-
# now tasks would be processed asynchronously
28-
p.set_size(1)
29-
ifpy2:
30-
assertp.size()==1
31-
3224
# A task performing processing on items from an iterator
3325
t=IteratorThreadTask(iter(list(range(10))),"power",lambdai: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
fromasync.threadimportterminate_threads
2323
fromasync.utilimportcpu_count
2424

25-
importthreading
2625
importtime
2726
importsys
2827

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

382381
@terminate_threads
383382
deftest_base(self):
384-
max_wait_attempts=3
385-
sleep_time=0.1
386-
formcinrange(max_wait_attempts):
387-
# wait for threads to die
388-
iflen(threading.enumerate())!=1:
389-
time.sleep(sleep_time)
390-
# END for each attempt
391-
assertlen(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-
assertp.size()==0
397-
398-
# increase and decrease the size
399-
num_threads=len(threading.enumerate())
400-
foriinrange(self.max_threads):
401-
p.set_size(i)
402-
ifpy2:
403-
assertp.size()==i
404-
assertlen(threading.enumerate())==num_threads+i
405-
406-
foriinrange(self.max_threads,-1,-1):
407-
p.set_size(i)
408-
ifpy2:
409-
assertp.size()==i
410-
385+
# default pools have no workers - and threading was removed entirely ...
411386
assertp.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-
assertlen(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-
ifpy2:
464-
assertp.size()==1
465-
assertlen(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-
ifpy2:
471-
assertlen(threading.enumerate())==num_threads
472-
473-
p=ThreadPool(1)
474-
ifpy2:
475-
assertlen(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-
fromqueueimportQueue
15-
exceptImportError:
16-
fromQueueimportQueue
17-
1813
importsys
1914
importtime
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
ifinspect.ismethod(routine):
182181
ifroutine.__self__isNone:
183-
rval=routine(self,arg)
182+
routine(self,arg)
184183
else:
185-
rval=routine(arg)
184+
routine(arg)
186185
elifinspect.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
exceptStopProcessing:
200199
break
201200
exceptExceptionase:
202-
log.error("%s: Task%sraised 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)

[8]ページ先頭

©2009-2025 Movatter.jp