本文整理汇总了Python中multiprocessing.Queue.pop方法的典型用法代码示例。如果您正苦于以下问题:Python Queue.pop方法的具体用法?Python Queue.pop怎么用?Python Queue.pop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类multiprocessing.Queue
的用法示例。
在下文中一共展示了Queue.pop方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Controller
# 需要导入模块: from multiprocessing import Queue [as 别名]
# 或者: from multiprocessing.Queue import pop [as 别名]
class Controller(object):
def __init__(self):
motor = get_motor(motor_debug)
trigger = get_trigger(debug)
self.motor = motor
self.video_tracker = None
print "CONNECTING Motor"
motor.connect()
print "CONNECTING Trigger"
self.trigger = trigger.Trigger()
print "CONNECTING Joystick"
self.init_joystick()
self.manual = False
self.x = None
self.y = None
self.fire_duration = 200
self.video_tracker = None
def _unused_init_detect_process(self):
self.video_in = Queue()
self.video_out = Queue()
self.detect_process = DetectProcess(inq=self.video_in, outq=self.video_out)
self.detect_process.start()
def on_frame(self, b):
ret = inp = numpy.fromstring(b.data, dtype=numpy.uint8).reshape(480, 720, 3)
if not self.video_tracker:
self.video_tracker = VideoTracker(initial_frame=inp, on_cx_cy=self.on_cx_cy)
else:
ret = self.video_tracker.on_frame(inp)
return gst.Buffer(ret)
def on_frame_process(self, b):
ret = inp = numpy.fromstring(b.data, dtype=numpy.uint8).reshape(480, 720, 3)
print "pushing"
self.video_in.push("test")
print "popping"
ret_unused = self.video_out.pop()
assert ret_unused == "testout"
print "popped"
return gst.Buffer(ret)
def init_joystick(self):
self.j = joystick.Joystick()
self.j.connect("axis", self.on_axis)
self.j.connect("button", self.on_button)
def on_axis(self, signal, code, value):
print "on_axis %s %s" % (code, value)
# print "on_axis %d, %d" % (code, value)
if code not in [0, 1, 2]:
return
if code == 0:
self.x = value
if self.manual:
self.motor.theta.set(state.x - 127)
elif code == 1:
self.y = value
if self.manual:
self.motor.pitch.set(state.y - 127)
else:
fire_duration = 100 + (float(value) / 255.0) * 900
print "joy: %d => fire dur %d" % (value, fire_duration)
self.fire_duration = int(fire_duration)
def on_button(self, signal, code, value):
print "on_button: %d, %d" % (code, value)
if value != 1 or code != 0:
return
print " **** FIRE ****"
self.trigger.fire(self.fire_duration)
def on_cx_cy(self, cx, cy):
# print "controller: got (%d, %d)" % (cx, cy)
cx -= 720 / 2
cy -= 480 / 2
for axis, val in [(self.motor.theta, cx), (self.motor.pitch, cy)]:
if abs(val) > 10:
print "action %r" % axis
axis.set(200 if cx > 0 else -200)