Chương trình xoắn của tôi hoạt động nhưng bây giờ tôi gặp vấn đề với một trong các lò phản ứng của tôi không chuyển ưu tiên cho các lò phản ứng khác. Tôi muốn các lò phản ứng controlListener để làm một lần lặp và sau đó vượt qua ưu tiên cho các lò phản ứng in ấn.Lỗi logic xoắn
#Random class as proof of concept
class printStuffs(object):
print "counting "
printerCount = 0
def count(self):
self.printerCount = self.printerCount + 1
print ("the counter is at " + str(self.printerCount))
##########################################################################
## The control listneer class is designed to kill given reactor threads ##
## on demand from something once it recieves a signal it is supposed ##
## to do one ieteration then release ##
##########################################################################
class controlListener(object):
counter = 20
def count(self):
if self.counter == 0:
print "Killing Process"
reactor.stop()
else:
print self.counter, '...'
self.counter -= 1
reactor.callLater(1, self.count)
from twisted.internet import reactor
print "Printing random stuff"
reactor.callWhenRunning(printStuffs().count)
print "Intializing kill listner"
reactor.callWhenRunning(controlListener().count)
reactor.run()
print "Process killed"
đây là sản phẩm
Printing random stuff
Intializing kill listner
the counter is at 1
20 ...
19 ...
18 ...
17 ...
16 ...
15 ...
14 ...
13 ...
12 ...
11 ...
10 ...
9 ...
8 ...
7 ...
6 ...
5 ...
4 ...
3 ...
2 ...
1 ...
Killing Process
Process killed
Tôi muốn nó để làm một cái gì đó giống như
the counter is at 1
20 ...
the counter is at 2
the counter is at 3
19 ...
, vv
Bất kỳ ý tưởng?
Tôi không bao giờ sử dụng xoắn, nhưng nó có thể được rằng 'printStuffs.count()' chỉ đơn giản là không sử dụng 'reactor.callLater()' để sắp xếp lại chính nó như 'controlListener.count()' không? – Norman
bạn nhận được nó, nếu bạn muốn bản sao tín dụng của bạn đăng bài vào một câu trả lời thực tế và tôi sẽ trao nó. –
Bạn đã nhận được câu trả lời nhưng tôi chỉ muốn thông báo rằng có một LoopingCall bị xoắn (https://twistedmatrix.com/documents/current/api/twisted.internet.task.LoopingCall.html), cho phép bạn không phải rescedule các cuộc gọi lặp đi lặp lại theo cách thủ công. –