当前位置: 首页>>代码示例>>Python>>正文


Python Pipe.recv_bytes方法代码示例

本文整理汇总了Python中multiprocessing.Pipe.recv_bytes方法的典型用法代码示例。如果您正苦于以下问题:Python Pipe.recv_bytes方法的具体用法?Python Pipe.recv_bytes怎么用?Python Pipe.recv_bytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在multiprocessing.Pipe的用法示例。


在下文中一共展示了Pipe.recv_bytes方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_cython_wrapper

# 需要导入模块: from multiprocessing import Pipe [as 别名]
# 或者: from multiprocessing.Pipe import recv_bytes [as 别名]
def test_cython_wrapper():
    descs, uris = plutosdr.scan_devices()
    plutosdr.set_tx(False)
    print("Devices", descs)
    print("Open", plutosdr.open(uris[0]))
    print("Set Freq to 433.92e6", plutosdr.set_center_freq(int(433.92e6)))
    print("Set Sample Rate to 2M", plutosdr.set_sample_rate(int(2.5e6)))
    print("Set bandwidth to 4M", plutosdr.set_bandwidth(int(4e6)))
    print("Set gain to 10", plutosdr.set_rf_gain(10))

    print("prepare rx", plutosdr.setup_rx())

    parent_conn, child_conn = Pipe()

    for i in range(10):
        plutosdr.receive_sync(child_conn)
        data = parent_conn.recv_bytes()
        print(np.frombuffer(data, dtype=np.int16))

    print(plutosdr.get_tx())
    print("Close", plutosdr.close())

    plutosdr.set_tx(True)

    print("Open", plutosdr.open(uris[0]))
    print("Setup tx", plutosdr.setup_tx())
    print("Set Freq to 433.92e6", plutosdr.set_center_freq(int(433.92e6)))
    print("Set Sample Rate to 2M", plutosdr.set_sample_rate(int(2.5e6)))
    print("Set bandwidth to 4M", plutosdr.set_bandwidth(int(4e6)))
    print("Set gain to 10", plutosdr.set_rf_gain(-89))

    print("Send", plutosdr.send_sync(np.zeros(4096, dtype=np.int16)))

    print("Close", plutosdr.close())
开发者ID:jopohl,项目名称:urh,代码行数:36,代码来源:TestPlutoSDR.py

示例2: test_multiprocessing_pipe

# 需要导入模块: from multiprocessing import Pipe [as 别名]
# 或者: from multiprocessing.Pipe import recv_bytes [as 别名]
 def test_multiprocessing_pipe(self):
     parent_conn, child_conn = Pipe()
     p = Process(target=f, args=(child_conn,))
     p.start()
     for _ in range(5):
         while parent_conn.poll():
             print("Got from client", parent_conn.recv_bytes())  # prints "[42, None, 'hello']"
         time.sleep(1)
     parent_conn.send_bytes(b"stop")
     p.join()
开发者ID:Cyber-Forensic,项目名称:urh,代码行数:12,代码来源:TestRTLSDRPipe.py

示例3: test_cython_wrapper

# 需要导入模块: from multiprocessing import Pipe [as 别名]
# 或者: from multiprocessing.Pipe import recv_bytes [as 别名]
    def test_cython_wrapper(self):
        result = airspy.open()
        print("Open:", airspy.error_name(result), result)

        sample_rates = airspy.get_sample_rates()
        print("Samples rates:", sample_rates)

        result = airspy.set_sample_rate(10**6)
        print("Set sample rate", airspy.error_name(result), result)

        result = airspy.set_center_frequency(int(433.92e6))
        print("Set center frequency", airspy.error_name(result), result)

        result = airspy.set_if_rx_gain(5)
        print("Set lna gain", airspy.error_name(result), result)

        result = airspy.set_rf_gain(8)
        print("Set mixer gain", airspy.error_name(result), result)

        result = airspy.set_baseband_gain(10)
        print("Set vga gain", airspy.error_name(result), result)

        parent_conn, child_conn = Pipe()

        result = airspy.start_rx(child_conn.send_bytes)
        print("Set start rx", airspy.error_name(result), result)

        time.sleep(0.01)
        print(np.fromstring(parent_conn.recv_bytes(8*65536), dtype=np.complex64))

        print("Closing")

        parent_conn.close()
        child_conn.close()

        result = airspy.stop_rx()
        print("Set stop rx", airspy.error_name(result), result)

        result = airspy.close()
        print("Close:", airspy.error_name(result), result)
开发者ID:Cyber-Forensic,项目名称:urh,代码行数:42,代码来源:TestAirSpy.py

示例4: index

# 需要导入模块: from multiprocessing import Pipe [as 别名]
# 或者: from multiprocessing.Pipe import recv_bytes [as 别名]
 def index(self, trans, mako = 'analyze', **kwd):
     if kwd.has_key('rerun_hda_id'):
         self._import_job_params(trans, kwd['rerun_hda_id'])
                 
     my_end, your_end = Pipe()
     if isinstance(mako, list):
         mako = mako[0]
     proc = Process(target=self.__index_pipe, args=(your_end,trans,str(mako)))
     proc.start()
     html = ''
     if proc.is_alive():
         if my_end.poll(120):
             html = my_end.recv_bytes()
             my_end.close()
         else:
             log.warn('fork timed out after 120 sec')
     else:
         log.warn('fork died on startup')
     proc.join(1)
     if proc.is_alive():
         proc.terminate()
         log.warn('fork did not exit, terminated.')
     return html
开发者ID:Anderrb,项目名称:Dynamic-benchmark,代码行数:25,代码来源:hyper.py

示例5: main

# 需要导入模块: from multiprocessing import Pipe [as 别名]
# 或者: from multiprocessing.Pipe import recv_bytes [as 别名]
def main(which="PipedService"):
  print "main(): pid = {pid}, ppid = {ppid}".format(pid=os.getpid(), ppid=os.getppid())

  if which == "PipedService":
    print "main(): Starting PipedService process..."
    pipeToProc, pipeToMain = Pipe()
    proc = PipedService(pipeToMain)
    proc.start()
    
    sleep(1)  # [debug] wait a bit to flush out all messages from child processes
    proc.test()  # [debug] test self and parent PIDs
    while proc.is_alive():
      command = raw_input("main(): Command : ")
      if proc.is_alive():
        pipeToProc.send_bytes(command)
        print "main(): Response: {0}".format(pipeToProc.recv_bytes())
      else:
        print "main(): Oops! Process already died."

    print "main(): Done; joining on process(es)..."
    proc.join()
  elif which == "QueuedService":
    print "main(): Starting QueuedService child process..."
    service = QueuedService()
    service.start()
    
    print "main(): Starting cannedLoop() child process..."
    cannedCommands = ["Hi", "How", "is", "it going?", "quit"]
    pCannedLoop = Process(target=cannedLoop, args=(service, cannedCommands, 5))
    pCannedLoop.start()

    print "main(): Starting interactiveLoop() (NOTE: Not a child process)..."
    interactiveLoop(service)
    
    print "main(): Joining on process(es)..."
    pCannedLoop.join()
    service.join()
    print "main(): Done."
  elif which == "MultiPipedService":
    print "main(): Starting MultiPipedService child process..."
    service = MultiPipedService()
    serviceHelper1 = service.addClient()
    serviceHelper2 = service.addClient()
    service.start()  # NOTE must addClient()s before calling start()
    
    sleep(1)  # let other process start-up messages to pass through
    print "main(): Starting cannedLoop() child process..."
    cannedCommands = ["Hi", "How", "is", "it going?", "quit"]
    pCannedLoop = Process(target=cannedLoop, args=(serviceHelper1, cannedCommands, 2))
    pCannedLoop.start()

    sleep(1)  # let other process start-up messages to pass through
    print "main(): Starting interactive loop..."
    while True:
      command = raw_input("Command > ")
      if not service.is_alive():
        print "main(): Oops! Service already dead; aborting..."
        break
      response = serviceHelper2.runCommandSync(command)
      print "Response: {0}".format(response)
      if command == "quit":
        break
    print "main(): Interactive loop terminated."
    
    print "main(): Joining on process(es)..."
    pCannedLoop.join()
    service.join()  # MultiPipedService automatically closes client connections on quit
    print "main(): Done."
  elif which == "SynchronizedService":
    print "main(): Starting SynchronizedService child process..."
    service = SynchronizedService()
    service.start()
    
    sleep(1)  # let other process start-up messages to pass through
    print "main(): Starting cannedLoop() child process..."
    cannedCommands = ["Hi", "How", "is", "it going?", "quit"]
    pCannedLoop = Process(target=cannedLoop, args=(service, cannedCommands, 2))
    pCannedLoop.start()

    sleep(1)  # let other process start-up messages to pass through
    print "main(): Starting interactive loop..."
    while True:
      command = raw_input("Command > ")
      if not service.is_alive():
        print "main(): Oops! Service already dead; aborting..."
        break
      response = service.runCommandSync(command)
      print "Response: {0}".format(response)
      if command == "quit":
        break
    print "main(): Interactive loop terminated."
    
    print "main(): Joining on process(es)..."
    pCannedLoop.join()
    service.join()  # MultiPipedService automatically closes client connections on quit
    print "main(): Done."
  else:
    print "main(): Unknown service type \"{0}\"".format(which)
开发者ID:IEEERobotics,项目名称:high-level,代码行数:100,代码来源:proc-test.py

示例6: print

# 需要导入模块: from multiprocessing import Pipe [as 别名]
# 或者: from multiprocessing.Pipe import recv_bytes [as 别名]
w_h.close()
print(r_h.read())
r_h.close()
os.unlink('/tmp/fifo')


# Pipe/message ###################################################
# Like message, can send and receive picklable objects.
# Implemented by pipe or socket.
p1, p2 = Pipe()

p1.send([1, 2, 'a'])
print(p2.recv())

p2.send_bytes('hello world', 6, 5)  # offset=6, size=5
print(p1.recv_bytes())              # get 'world'

p1.close()
p2.close()

# Queue ##########################################################
# The object is stored in collections.deque temporarily.
# A thread is running background, writing the object into
# Pipe. So, object should be picklable.
pool = Queue()
pool.put(['a', 1])
print(pool.get(True))


# mmap and shared memory #########################################
# call map with MAP-SHARED before calling fork
开发者ID:huxt2014,项目名称:python-examples,代码行数:33,代码来源:process.py

示例7: test_cython_wrapper

# 需要导入模块: from multiprocessing import Pipe [as 别名]
# 或者: from multiprocessing.Pipe import recv_bytes [as 别名]
    def test_cython_wrapper(self):
        print("Devices:", limesdr.get_device_list())
        # print("Open:", limesdr.open("LimeSDR-USB, media=USB 3.0, module=STREAM, addr=1d50:6108, serial=0009060B0049180A"))
        print("Open:", limesdr.open())
        print("-" * 20)

        print("Is Open 0:", limesdr.is_open(0))
        print("Is Open 1:", limesdr.is_open(1))
        print("Init", limesdr.init())
        limesdr.set_tx(True)
        self.assertTrue(limesdr.get_tx())
        #print(limesdr.IS_TX)
        print("Num Channels TX:", limesdr.get_num_channels())
        print("TX antennas", limesdr.get_antenna_list())
        limesdr.set_tx(False)
        self.assertFalse(limesdr.get_tx())

        print("Num Channels RX:", limesdr.get_num_channels())
        limesdr.CHANNEL = 0
        print("Enable RX Channel 0:", limesdr.enable_channel(True, False, 0))

        #path = os.path.realpath(os.path.join(__file__, "..", "..", "src", "urh", "dev", "native", "lime.ini"))
        #print(path)
        #limesdr.load_config(path)
        #limesdr.save_config("/tmp/lime_test.ini")

        clocks = ["LMS_CLOCK_REF", "LMS_CLOCK_SXR", "LMS_CLOCK_SXT", "LMS_CLOCK_CGEN", "LMS_CLOCK_RXTSP", "LMS_CLOCK_TXTSP"]

        for i, clock in enumerate(clocks):
            print(clock, limesdr.get_clock_freq(i))

        limesdr.print_last_error()
        print("RX Sample Rate Range:", limesdr.get_sample_rate_range())
        print("RX Channel 0 Sample Rate:", limesdr.get_sample_rate())
        print("Set Sample Rate:", limesdr.set_sample_rate(2e6))
        print("RX Channel 0 Sample Rate:", limesdr.get_sample_rate())

        limesdr.print_last_error()
        print("RX Frequency Range:", limesdr.get_center_frequency_range())
        print("RX 0 center freq:", limesdr.get_center_frequency())
        print("RX 0 set center freq:", limesdr.set_center_frequency(433.92e6))
        print("RX 0 center freq:", limesdr.get_center_frequency())

        limesdr.print_last_error()
        print("RX 0 gain", limesdr.get_normalized_gain())
        print("RX 0 set gain", limesdr.set_normalized_gain(0.5))
        print("RX 0 gain", limesdr.get_normalized_gain())

        limesdr.print_last_error()
        print("RX Bandwidth Range", limesdr.get_lpf_bandwidth_range())
        print("RX 0 Bandwidth", limesdr.get_lpf_bandwidth())
        print("RX 0 set Bandwidth", limesdr.set_lpf_bandwidth(20e6))
        print("RX 0 Bandwidth", limesdr.get_lpf_bandwidth())

        limesdr.print_last_error()
        print("RX 0 calibrate:", limesdr.calibrate(20e6))

        limesdr.print_last_error()
        antenna_list = limesdr.get_antenna_list()
        print("RX 0 antenna list", antenna_list)
        print("RX 0 current antenna", limesdr.get_antenna(), antenna_list[limesdr.get_antenna()])
        print("RX 0 current antenna BW", limesdr.get_antenna_bw(limesdr.get_antenna()))

        print("Chip Temperature", limesdr.get_chip_temperature())

        parent_conn, child_conn = Pipe()

        for _ in range(2):
            limesdr.print_last_error()
            print("Setup stream", limesdr.setup_stream(1000))
            print("Start stream", limesdr.start_stream())
            limesdr.recv_stream(child_conn, 1000, 100)
            print("Stop stream", limesdr.stop_stream())
            print("Destroy stream", limesdr.destroy_stream())

            print(parent_conn.recv_bytes())

        limesdr.set_tx(True)
        self.assertTrue(limesdr.get_tx())
        samples_to_send = np.ones(32768, dtype=np.complex64)
        for _ in range(2):
            limesdr.print_last_error()
            print("Setup stream", limesdr.setup_stream(4000000000))
            print("Start stream", limesdr.start_stream())
            print("Send samples", limesdr.send_stream(samples_to_send, 100))
            print("Stop stream", limesdr.stop_stream())
            print("Destroy stream", limesdr.destroy_stream())

        print("-" * 20)
        print("Close:", limesdr.close())
        print("Is Open 0:", limesdr.is_open(0))
        print("Is Open 1:", limesdr.is_open(1))
开发者ID:Cyber-Forensic,项目名称:urh,代码行数:94,代码来源:TestLimeSDR.py

示例8: Device

# 需要导入模块: from multiprocessing import Pipe [as 别名]
# 或者: from multiprocessing.Pipe import recv_bytes [as 别名]

#.........这里部分代码省略.........
        self.transmit_process.start()

    def stop_tx_mode(self, msg):
        try:
            self.parent_ctrl_conn.send(self.Command.STOP.name)
        except (BrokenPipeError, OSError) as e:
            logger.debug("Closing parent control connection: " + str(e))

        logger.info("{0}: Stopping TX Mode: {1}".format(self.__class__.__name__, msg))

        if hasattr(self, "transmit_process") and self.transmit_process.is_alive():
            self.transmit_process.join(self.JOIN_TIMEOUT)
            if self.transmit_process.is_alive():
                logger.warning("{0}: Transmit process is still alive, terminating it".format(self.__class__.__name__))
                self.transmit_process.terminate()
                self.transmit_process.join()

        self.is_transmitting = False
        try:
            self.parent_ctrl_conn.close()
        except OSError as e:
            logger.exception(e)

        try:
            self.child_ctrl_conn.close()
        except OSError as e:
            logger.exception(e)

    @staticmethod
    def unpack_complex(buffer):
        pass

    @staticmethod
    def pack_complex(complex_samples: np.ndarray):
        pass

    def read_device_messages(self):
        while self.is_receiving or self.is_transmitting:
            try:
                message = self.parent_ctrl_conn.recv()
                try:
                    splitted = message.split(":")
                    action = ":".join(splitted[:-1])
                    return_code = splitted[-1]
                    self.log_retcode(int(return_code), action)
                except ValueError:
                    self.device_messages.append("{0}: {1}".format(self.__class__.__name__, message))
            except (EOFError, UnpicklingError, OSError, ConnectionResetError) as e:
                logger.info("Exiting read device message thread due to " + str(e))
                break
        self.is_transmitting = False
        self.is_receiving = False
        logger.debug("Exiting read device errors thread")

    def read_receiving_queue(self):
        while self.is_receiving:
            try:
                byte_buffer = self.parent_data_conn.recv_bytes()
                samples = self.unpack_complex(byte_buffer)
                n_samples = len(samples)
                if n_samples == 0:
                    continue
            except OSError as e:
                logger.exception(e)
                continue
            except EOFError:
                logger.info("EOF Error: Ending receive thread")
                break

            if self.current_recv_index + n_samples >= len(self.receive_buffer):
                if self.resume_on_full_receive_buffer:
                    self.current_recv_index = 0
                    if n_samples >= len(self.receive_buffer):
                        n_samples = len(self.receive_buffer) - 1
                else:
                    self.stop_rx_mode(
                        "Receiving buffer is full {0}/{1}".format(self.current_recv_index + n_samples,
                                                                  len(self.receive_buffer)))
                    return

            self.receive_buffer[self.current_recv_index:self.current_recv_index + n_samples] = samples[:n_samples]
            self.current_recv_index += n_samples

            if self.emit_data_received_signal:
                self.data_received.emit(samples)

        logger.debug("Exiting read_receive_queue thread.")

    def init_send_parameters(self, samples_to_send: np.ndarray = None, repeats: int = None, resume=False):
        if samples_to_send is not None:
            self.samples_to_send = samples_to_send
            self.send_buffer = None

        if self.send_buffer is None:
            self.send_buffer = self.pack_complex(self.samples_to_send)
        elif not resume:
            self.current_sending_repeat = 0

        if repeats is not None:
            self.sending_repeats = repeats
开发者ID:NickMinnellaCS96,项目名称:urh,代码行数:104,代码来源:Device.py


注:本文中的multiprocessing.Pipe.recv_bytes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。