Skip to content

Commit

Permalink
Merge pull request #6 from real-easypy/callable-concurrent-fix
Browse files Browse the repository at this point in the history
concurrency: fix arg handling in concurrent calls in recent feature u…
  • Loading branch information
koreno authored Jun 17, 2020
2 parents 91372dd + 0e2ed4d commit c3850ec
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
11 changes: 6 additions & 5 deletions easypy/concurrency.py
Original file line number Diff line number Diff line change
Expand Up @@ -974,8 +974,9 @@ def __repr__(self):
flags += 'T'
return "<%s[%s] '%s'>" % (self.__class__.__name__, self.threadname, flags)

def _logged_func(self, kwargs=None):
kwargs = {**self.kwargs, **(kwargs or {})}
def _logged_func(self, *args, **kwargs):
args = self.args + args
kwargs = {**self.kwargs, **kwargs}
stack = ExitStack()
self.exc = None
self.timer = Timer()
Expand All @@ -986,7 +987,7 @@ def _logged_func(self, kwargs=None):
stack.enter_context(_logger.suppressed())
_logger.debug("%s - starting", self)
while True:
self._result = self.func(*self.args, **kwargs)
self._result = self.func(*args, **kwargs)
if not self.loop:
return
if self.wait(self.sleep):
Expand Down Expand Up @@ -1046,10 +1047,10 @@ def paused(self):

@contextmanager
def _running(self, *args, **kwargs):
func = lambda *args, **kwargs: self._logged_func(*args, **kwargs)
func = lambda: self._logged_func(*args, **kwargs)

if DISABLE_CONCURRENCY:
self._logged_func(*args, **kwargs)
func()
yield self
return

Expand Down
13 changes: 11 additions & 2 deletions tests/test_concurrency.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,18 @@ def test_thread_stacks():


def test_call_concurrent():
func = lambda a, b: a + b
func = lambda a, b: a * 10 + b
c = concurrent(func, 1, b=2, threadname='add')
assert c() == 3
assert c() == 12

c = concurrent(func, 1, 2, threadname='add')
assert c() == 12

c = concurrent(func, 1, threadname='add')
assert c(2) == 12

c = concurrent(func, threadname='add')
assert c(1, 2) == 12


def test_call_concurrent_timeout():
Expand Down

0 comments on commit c3850ec

Please sign in to comment.