async fuction

A

aleksey

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)
 
M

MRAB

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top