Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #36668 > unrolled thread
| Started by | aleksey@silk.bz |
|---|---|
| First post | 2013-01-11 20:43 -0800 |
| Last post | 2013-01-12 18:01 +0000 |
| Articles | 3 — 3 participants |
Back to article view | Back to comp.lang.python
async fuction aleksey@silk.bz - 2013-01-11 20:43 -0800
Re: async fuction Chris Angelico <rosuav@gmail.com> - 2013-01-12 15:52 +1100
Re: async fuction MRAB <python@mrabarnett.plus.com> - 2013-01-12 18:01 +0000
| From | aleksey@silk.bz |
|---|---|
| Date | 2013-01-11 20:43 -0800 |
| Subject | async fuction |
| Message-ID | <6bcc6374-88bb-47a0-b2c3-8082794ed158@googlegroups.com> |
Hello.
Can someone help me to resolv error.
code:
import threading
class TimeoutError(RuntimeError):
pass
class AsyncCall(object):
def __init__(self, fnc, callback = None):
self.Callable = fnc
self.Callback = callback
def __call__(self, *args, **kwargs):
self.Thread = threading.Thread(target = self.run, name = self.Callable.__name__, args = args, kwargs = kwargs)
self.Thread.start()
return self
def wait(self, timeout = None):
self.Thread.join(timeout)
if self.Thread.isAlive():
raise TimeoutError()
else:
return self.Result
def run(self, *args, **kwargs):
self.Result = self.Callable(*args, **kwargs)
if self.Callback:
self.Callback(self.Result)
class AsyncMethod(object):
def __init__(self, fnc, callback=None):
self.Callable = fnc
self.Callback = callback
def __call__(self, *args, **kwargs):
return AsyncCall(self.Callable, self.Callback)(*args, **kwargs)
def Async(fnc = None, callback = None):
if fnc == None:
def AddAsyncCallback(fnc):
return AsyncMethod(fnc, callback)
return AddAsyncCallback
else:
return AsyncMethod(fnc, callback)
@Async
def fnc(pi, pp):
print "fnc-"
i=pi
while ( i < 10000000 ) :
i=i+1
print "fnc+"
pass
@Async
def fnc1(pp):
print "fnc1-",pp
@Async
def fnc2():
print "fnc2-"
i=0
while ( i < 100000 ) :
i=i+1
print "fnc2+"
pass
fnc(i=0,pp="123123")
fnc1()
error:
Exception in thread fnc1:
Traceback (most recent call last):
File "C:\Python27\lib\threading.py", line 551, in __bootstrap_inner
self.run()
File "C:\Python27\lib\threading.py", line 504, in run
self.__target(*self.__args, **self.__kwargs)
File "C:/Users/rootiks/YandexDisk/py/myftpbackup/asynclib.py", line 26, in run
self.Result = self.Callable(*args, **kwargs)
TypeError: fnc1() takes exactly 1 argument (0 given)
[toc] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2013-01-12 15:52 +1100 |
| Message-ID | <mailman.426.1357966350.2939.python-list@python.org> |
| In reply to | #36668 |
On Sat, Jan 12, 2013 at 3:43 PM, <aleksey@silk.bz> wrote:
> def fnc1(pp):
> print "fnc1-",pp
>
> fnc1()
Like the message says, the function has been defined to take one
argument, and you're giving it none. Try giving it an argument:
fnc1("five-minute")
ChrisA
[toc] | [prev] | [next] | [standalone]
| From | MRAB <python@mrabarnett.plus.com> |
|---|---|
| Date | 2013-01-12 18:01 +0000 |
| Message-ID | <mailman.454.1358013700.2939.python-list@python.org> |
| In reply to | #36668 |
On 2013-01-12 04:43, aleksey@silk.bz wrote: > Hello. > > Can someone help me to resolv error. > > code: > [snip] > > @Async > def fnc(pi, pp): > > print "fnc-" > i=pi > while ( i < 10000000 ) : > i=i+1 > print "fnc+" > pass > > @Async > def fnc1(pp): > print "fnc1-",pp > > > @Async > def fnc2(): > print "fnc2-" > i=0 > while ( i < 100000 ) : > i=i+1 > print "fnc2+" > pass > > fnc(i=0,pp="123123") > fnc1() > > > error: > > Exception in thread fnc1: > Traceback (most recent call last): > File "C:\Python27\lib\threading.py", line 551, in __bootstrap_inner > self.run() > File "C:\Python27\lib\threading.py", line 504, in run > self.__target(*self.__args, **self.__kwargs) > File "C:/Users/rootiks/YandexDisk/py/myftpbackup/asynclib.py", line 26, in run > self.Result = self.Callable(*args, **kwargs) > TypeError: fnc1() takes exactly 1 argument (0 given) > 1. You're calling function 'fnc' with keyword arguments 'i' and 'pp'; it's expecting 'pi' and 'pp'. 2. You're calling function 'fnc1' with no arguments; it's expecting one argument.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web