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