मुझे नेटवर्क कोर्स में एक प्रोग्राम लिखना है जो चुनिंदा दोहराव की तरह कुछ है लेकिन एक टाइमर की आवश्यकता है। गूगल में खोज के बाद मैंने पाया कि threading.Timer मेरी मदद कर सकते हैं, मैं सिर्फ परीक्षण के लिए एक साधारण प्रोग्राम लिखा कैसे threading.Timer काम है कि इस था:थ्रेडिंग। टिमर()
import threading
def hello():
print "hello, world"
t = threading.Timer(10.0, hello)
t.start()
print "Hi"
i=10
i=i+20
print i
इस कार्यक्रम को सही ढंग से चलाने के लिए। लेकिन जब मैं एक तरीका है कि जैसे पैरामीटर देने में हैलो समारोह परिभाषित करने की कोशिश:
import threading
def hello(s):
print s
h="hello world"
t = threading.Timer(10.0, hello(h))
t.start()
print "Hi"
i=10
i=i+20
print i
बाहर डाल दिया है:
hello world
Hi
30
Exception in thread Thread-1:
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/threading.py", line 522, in __bootstrap_inner
self.run()
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/threading.py", line 726, in run
self.function(*self.args, **self.kwargs)
TypeError: 'NoneType' object is not callable
मैं नहीं कर सकते समझ में समस्या क्या है! क्या कोई मेरी मदद कर सकता है?
बहुत बहुत धन्यवाद :) – sandra