My Twisted Arbeiten Programm, aber jetzt habe ich ein Problem mit einem meiner Reaktoren nicht vorrangig auf die anderen übergeben. Ich möchte, dass der controlListener-Reaktor eine Iteration ausführt und dann die Priorität an den Druckreaktor übergibt.Verdrehte Logik Fehler
#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"
Hier ist die Ausgabe
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
ich es will, etwas tun wie
the counter is at 1
20 ...
the counter is at 2
the counter is at 3
19 ...
usw.
Irgendwelche Ideen?
ich nie verdreht verwendet, aber es könnte sein, dass 'printStuffs.count()' 'einfach nicht nicht verwendet reactor.callLater()' selbst neu zu planen wie 'controlListener.count()' tut? – Norman
Sie haben es, wenn Sie den Kredit kopieren Sie Ihre Post in eine tatsächliche Antwort wollen, und ich werde es vergeben. –
Sie haben bereits eine Antwort erhalten, aber ich möchte nur feststellen, dass es ein LoopingCall in verdreht ist (https://twistedmatrix.com/documents/current/api/twisted.internet.task.LoopingCall.html), der es ermöglicht Sie können wiederholte Anrufe nicht manuell neu skalieren. –