本文整理汇总了Python中multiprocessing.connection.Connection方法的典型用法代码示例。如果您正苦于以下问题:Python connection.Connection方法的具体用法?Python connection.Connection怎么用?Python connection.Connection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类multiprocessing.connection
的用法示例。
在下文中一共展示了connection.Connection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init_device
# 需要导入模块: from multiprocessing import connection [as 别名]
# 或者: from multiprocessing.connection import Connection [as 别名]
def init_device(cls, ctrl_connection: Connection, is_tx: bool, parameters: OrderedDict):
if not cls.setup_device(ctrl_connection, device_identifier=parameters["identifier"]):
return False
limesdr.enable_channel(True, is_tx, parameters[cls.Command.SET_CHANNEL_INDEX.name])
limesdr.set_tx(is_tx)
for parameter, value in parameters.items():
cls.process_command((parameter, value), ctrl_connection, is_tx)
antennas = limesdr.get_antenna_list()
ctrl_connection.send("Current normalized gain is {0:.2f}".format(limesdr.get_normalized_gain()))
ctrl_connection.send("Current antenna is {0}".format(antennas[limesdr.get_antenna()]))
ctrl_connection.send("Current chip temperature is {0:.2f}°C".format(limesdr.get_chip_temperature()))
return True
示例2: setup_device
# 需要导入模块: from multiprocessing import connection [as 别名]
# 或者: from multiprocessing.connection import Connection [as 别名]
def setup_device(cls, ctrl_connection: Connection, device_identifier):
device_identifier = device_identifier if isinstance(device_identifier, str) else ""
try:
device_identifier = re.search("(?<=\[).+?(?=\])", device_identifier).group(0)
except (IndexError, AttributeError):
pass
if not device_identifier:
_, uris = plutosdr.scan_devices()
try:
device_identifier = uris[0]
except IndexError:
ctrl_connection.send("Could not find a connected PlutoSDR")
return False
ret = plutosdr.open(device_identifier)
ctrl_connection.send("OPEN ({}):{}".format(device_identifier, ret))
return ret == 0
示例3: __init__
# 需要导入模块: from multiprocessing import connection [as 别名]
# 或者: from multiprocessing.connection import Connection [as 别名]
def __init__(self, process: Process, worker_id: int, conn: Connection):
self.process = process
self.worker_id = worker_id
self.conn = conn
self.previous_step: EnvironmentStep = EnvironmentStep.empty(worker_id)
self.previous_all_action_info: Dict[str, ActionInfo] = {}
self.waiting = False
示例4: __init__
# 需要导入模块: from multiprocessing import connection [as 别名]
# 或者: from multiprocessing.connection import Connection [as 别名]
def __init__(self, dataloader: DataLoader,
output_pipe: mpconnection.Connection,
index_pipe: mpconnection.Connection,
abort_event: multiprocessing.Event,
transforms: Callable,
process_id):
"""
Parameters
----------
dataloader : :class:`DataLoader`
the data loader which loads the data corresponding to the given
indices
output_pipe : :class:`multiprocessing.connection.Connection`
the pipe, the loaded data shoud be sent to
index_pipe : :class:`multiprocessing.connection.Connection`
the pipe to accept the indices
abort_event : class:`multiprocessing.Event`
the abortion event; will be set for every Exception;
If set: Worker terminates
transforms : :class:`collections.Callable`
the transforms to transform the data
process_id : int
the process id
"""
super().__init__()
self._data_loader = dataloader
self._output_pipe = output_pipe
self._input_pipe = index_pipe
self._abort_event = abort_event
self._process_id = process_id
self._transforms = transforms
示例5: rebuild_connection
# 需要导入模块: from multiprocessing import connection [as 别名]
# 或者: from multiprocessing.connection import Connection [as 别名]
def rebuild_connection(df, readable, writable):
fd = df.detach()
return Connection(fd, readable, writable)
示例6: test_shared_process_code_success
# 需要导入模块: from multiprocessing import connection [as 别名]
# 或者: from multiprocessing.connection import Connection [as 别名]
def test_shared_process_code_success():
# Setup
mock_target = MagicMock()
iso = MagicMock()
game_files_path = MagicMock()
on_finish_message = MagicMock()
progress_update = MagicMock()
process = MagicMock()
def process_effect(target, args):
output_pipe: connection.Connection = args[0]
output_pipe.send((False, "Message 1", 0.2))
output_pipe.send((False, "Message 2", 0.5))
output_pipe.send((True, None, 100))
return process
# Run
with patch("multiprocessing.Process", side_effect=process_effect,
autospec=work_around_pytest_qt_bug) as mock_process:
iso_packager._shared_process_code(mock_target, iso, game_files_path, on_finish_message, progress_update)
mock_process.assert_called_once_with(target=mock_target, args=(ANY, iso, game_files_path))
process.start.assert_called_once_with()
process.terminate.assert_called_once_with()
progress_update.assert_has_calls([
call("", 0),
call("Message 1", 0.2),
call("Message 2", 0.5),
call(on_finish_message, 1),
])
示例7: test_shared_process_code_failure
# 需要导入模块: from multiprocessing import connection [as 别名]
# 或者: from multiprocessing.connection import Connection [as 别名]
def test_shared_process_code_failure():
# Setup
mock_target = MagicMock()
iso = MagicMock()
game_files_path = MagicMock()
on_finish_message = MagicMock()
progress_update = MagicMock()
process = MagicMock()
def process_effect(target, args):
output_pipe: connection.Connection = args[0]
output_pipe.send((False, "Message 1", 0.2))
output_pipe.send((True, "You got an error!", 100))
return process
# Run
with patch("multiprocessing.Process", side_effect=process_effect,
autospec=work_around_pytest_qt_bug) as mock_process:
with pytest.raises(RuntimeError) as exception:
iso_packager._shared_process_code(mock_target, iso, game_files_path, on_finish_message, progress_update)
mock_process.assert_called_once_with(target=mock_target, args=(ANY, iso, game_files_path))
process.start.assert_called_once_with()
process.terminate.assert_called_once_with()
progress_update.assert_has_calls([
call("", 0),
call("Message 1", 0.2),
])
assert str(exception.value) == "You got an error!"
示例8: read_key
# 需要导入模块: from multiprocessing import connection [as 别名]
# 或者: from multiprocessing.connection import Connection [as 别名]
def read_key(lock: Lock, connection: Connection):
cache = get_cache_backend()
with lock:
connection.send(cache.get("TEST_KEY"))
示例9: setup_device
# 需要导入模块: from multiprocessing import connection [as 别名]
# 或者: from multiprocessing.connection import Connection [as 别名]
def setup_device(cls, ctrl_connection: Connection, device_identifier):
# identifier gets set in self.receive_process_arguments
device_number = int(device_identifier)
ret = rtlsdr.open(device_number)
ctrl_connection.send("OPEN (#{}):{}".format(device_number, ret))
return ret == 0
示例10: prepare_sync_receive
# 需要导入模块: from multiprocessing import connection [as 别名]
# 或者: from multiprocessing.connection import Connection [as 别名]
def prepare_sync_receive(cls, ctrl_connection: Connection):
ret = rtlsdr.reset_buffer()
ctrl_connection.send("RESET_BUFFER:" + str(ret))
return ret
示例11: receive_sync
# 需要导入模块: from multiprocessing import connection [as 别名]
# 或者: from multiprocessing.connection import Connection [as 别名]
def receive_sync(cls, data_conn: Connection):
data_conn.send_bytes(rtlsdr.read_sync())
示例12: enter_async_receive_mode
# 需要导入模块: from multiprocessing import connection [as 别名]
# 或者: from multiprocessing.connection import Connection [as 别名]
def enter_async_receive_mode(cls, data_connection: Connection, ctrl_connection: Connection):
ret = sdrplay.init_stream(cls.sdrplay_initial_gain, cls.sdrplay_initial_sample_rate, cls.sdrplay_initial_freq,
cls.sdrplay_initial_bandwidth, cls.sdrplay_initial_if_gain, data_connection)
ctrl_connection.send(
"Start RX MODE with \n FREQUENCY={}\n SAMPLE_RATE={}\n BANDWIDTH={}\n GAIN={}\n IF_GAIN={}:{}".format(
cls.sdrplay_initial_freq, cls.sdrplay_initial_sample_rate, cls.sdrplay_initial_bandwidth, cls.sdrplay_initial_gain, cls.sdrplay_initial_if_gain, ret))
return ret
示例13: init_device
# 需要导入模块: from multiprocessing import connection [as 别名]
# 或者: from multiprocessing.connection import Connection [as 别名]
def init_device(cls, ctrl_connection: Connection, is_tx: bool, parameters: OrderedDict) -> bool:
identifier = parameters["identifier"]
try:
device_list = sdrplay.get_devices()
device_number = int(identifier)
ctrl_connection.send("CONNECTED DEVICES: {}".format(", ".join(map(cls.device_dict_to_string, device_list))))
ret = sdrplay.set_device_index(device_number)
ctrl_connection.send("SET DEVICE NUMBER to {}:{}".format(device_number, ret))
except (TypeError, ValueError) as e:
logger.exception(e)
return False
device_model = device_list[device_number]["hw_version"]
sdrplay.set_gr_mode_for_dev_model(device_model)
if device_model == 2:
antenna = parameters[cls.Command.SET_ANTENNA_INDEX.name]
cls.process_command((cls.Command.SET_ANTENNA_INDEX.name, antenna), ctrl_connection, is_tx=False)
else:
ctrl_connection.send("Skipping antenna selection for RSP1 device")
cls.sdrplay_initial_freq = parameters[cls.Command.SET_FREQUENCY.name]
cls.sdrplay_initial_sample_rate = parameters[cls.Command.SET_SAMPLE_RATE.name]
cls.sdrplay_initial_bandwidth = parameters[cls.Command.SET_BANDWIDTH.name]
cls.sdrplay_initial_gain = parameters[cls.Command.SET_RF_GAIN.name]
cls.sdrplay_initial_if_gain = parameters[cls.Command.SET_IF_GAIN.name]
cls.sdrplay_device_index = identifier
return True
示例14: shutdown_device
# 需要导入模块: from multiprocessing import connection [as 别名]
# 或者: from multiprocessing.connection import Connection [as 别名]
def shutdown_device(cls, ctrl_conn: Connection, is_tx: bool):
if is_tx:
result = hackrf.stop_tx_mode()
ctrl_conn.send("STOP TX MODE:" + str(result))
else:
result = hackrf.stop_rx_mode()
ctrl_conn.send("STOP RX MODE:" + str(result))
result = hackrf.close()
ctrl_conn.send("CLOSE:" + str(result))
result = hackrf.exit()
ctrl_conn.send("EXIT:" + str(result))
return True
示例15: enter_async_receive_mode
# 需要导入模块: from multiprocessing import connection [as 别名]
# 或者: from multiprocessing.connection import Connection [as 别名]
def enter_async_receive_mode(cls, data_connection: Connection, ctrl_connection: Connection):
ret = hackrf.start_rx_mode(data_connection.send_bytes)
ctrl_connection.send("Start RX MODE:" + str(ret))
return ret