本文整理汇总了Python中sender.Sender.terminate方法的典型用法代码示例。如果您正苦于以下问题:Python Sender.terminate方法的具体用法?Python Sender.terminate怎么用?Python Sender.terminate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sender.Sender
的用法示例。
在下文中一共展示了Sender.terminate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: emulate
# 需要导入模块: from sender import Sender [as 别名]
# 或者: from sender.Sender import terminate [as 别名]
def emulate(args):
'''
Starts the Sender/Receiver process threads, sleeps for
args.RUNTIME, and terminates both threads. Returns a tuple of
lists: (s_log, r_log), where s_log is sender's log and r_log is
receiver's log.
'''
args.SENDER_TIMEOUT = float(args.SENDER_TIMEOUT)
args.RUNTIME = float(args.RUNTIME)
assert args.SENDER_TIMEOUT > 0
assert args.RUNTIME > 0
s = Sender(args.SENDER_TIMEOUT)
r = Receiver()
s.set_remote_endpoint(r)
r.set_remote_endpoint(s)
r.daemon = True
s.daemon = True
# Start the sender process.
s.start()
r.start()
try:
time.sleep(args.RUNTIME)
except KeyboardInterrupt:
print "Interrupted, terminating."
# We have to be careful with terminating the two threads, as they
# can only exit in specific states, and we can cause a deadlock.
# First, we terminate the sender, and wait for it to finish. Once
# this happens, we know that the receiver is in an ok terminal
# state, so we terminate it right after.
s.terminate()
s.join()
r.terminate()
r.join()
#s.log.append((([0,0], "S-TERM")))
#r.log.append((([0,0], "R-TERM")))
# At this point, the sender is not generating any more
# messages. But, we might have some oustanding messages in
# receiver's queue. So, process these, if any:
while not r.rx_queue.empty():
# Receive msg and generate any outstanding acks.
r.transition()
r.transition()
r.transition()
# Consume any outstanding acks on the sender's side.
s.consume_acks()
return (s.log, r.log)
示例2: GUI
# 需要导入模块: from sender import Sender [as 别名]
# 或者: from sender.Sender import terminate [as 别名]
class GUI(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QMainWindow.__init__(self,parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.addCarriers()
self.thread = Sender()
self.connect(self.ui.actionAbout, QtCore.SIGNAL('triggered()'), self.showAbout)
self.connect(self.ui.actionQuit, QtCore.SIGNAL('triggered()'), exit)
self.connect(self.ui.button, QtCore.SIGNAL('clicked()'), self.toggle)
self.connect(self.thread, QtCore.SIGNAL("finished()"), self.done)
self.connect(self.thread, QtCore.SIGNAL("terminated()"), self.done)
self.connect(self.thread, QtCore.SIGNAL("plusOne()"), self.plusOne)
self.connect(self.thread, QtCore.SIGNAL("sendingError()"), self.stop)
self.ui.server.setText('127.0.0.1:25') #set default
self.ui.message.setPlainText('SPAM!')
self.ui.statusBar().showMessage('Ready') #broken
def toggle(self):
self.state = self.ui.button.text()
if self.state == 'Start':
self.start()
if self.state == 'Stop':
self.stop()
def stop(self):
self.thread.terminate()
print('stoping')
self.done()
def done(self):
self.ui.button.setText('Start')
self.ui.phone.setEnabled(True)
self.ui.provider.setEnabled(True)
self.ui.server.setEnabled(True)
self.ui.tls.setEnabled(True)
self.ui.user.setEnabled(True)
self.ui.password.setEnabled(True)
self.ui.message.setEnabled(True)
def start(self):
if self.ui.phone.text() != '' and self.thread.connect(
self.ui.server.text(),
self.ui.user.text(),
self.ui.password.text(),
self.ui.tls.isChecked()
):
self.ui.button.setText('Stop')
self.ui.phone.setEnabled(False)
self.ui.provider.setEnabled(False)
self.ui.server.setEnabled(False)
self.ui.tls.setEnabled(False)
self.ui.user.setEnabled(False)
self.ui.password.setEnabled(False)
self.ui.message.setEnabled(False)
self.ui.lcd.display('0')
print('starting')
self.thread.toaddr = self.ui.phone.text() + self.providers[self.ui.provider.currentText()]
self.thread.msg = self.ui.message.toPlainText()
print('sending to:', self.thread.toaddr)
def plusOne(self):
self.ui.lcd.display(str(self.ui.lcd.intValue() + 1))
def showAbout(self):
self.about = QtGui.QWidget()
ui = Ui_About()
ui.setupUi(self.about)
ui.Version.setText(str(version))
self.connect(ui.pushButton, QtCore.SIGNAL('clicked()'),self.about.close)
self.about.show()
def addCarriers(self):
'''can get more from
http://www.emailtextmessages.com/
'''
self.providers = {
'Alltel':'@message.alltel.com',
'AT&T':'@txt.att.net',
'Boost Mobile':'@myboostmobile.com',
'Metro PCS':'@mymetropcs.com',
'Sprint':'@messaging.sprintpcs.com',
'T-Mobile':'@tmomail.net',
'US Cellular':'@email.uscc.net',
'Verizon':'@vtext.com',
'Virgin Mobile':'@vmobl.com',
'Gmail':'@gmail.com',
'Other':''
}
#.........这里部分代码省略.........