_id stringlengths 2 7 | title stringlengths 1 88 | partition stringclasses 3
values | text stringlengths 75 19.8k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q18700 | _setup_network | train | def _setup_network():
"""Setup platform specific network settings"""
global wlan
global secret
if sys.platform in PYCOM:
# Update secret as tuple with wlan mode for PyCom port.
wlan = network.WLAN(network.WLAN.STA)
secret = (network.WLAN.WPA2, settings.WIFI_PASSWORD)
else:
... | python | {
"resource": ""
} |
q18701 | _wifi_connect | train | def _wifi_connect():
"""Connects to WIFI"""
if not wlan.isconnected():
wlan.active(True)
print("NETWORK: connecting to network %s..." % settings.WIFI_SSID)
wlan.connect(settings.WIFI_SSID, secret)
while not wlan.isconnected():
print("NETWORK: waiting for connection...... | python | {
"resource": ""
} |
q18702 | disable_ap | train | def disable_ap():
"""Disables any Accesspoint"""
wlan = network.WLAN(network.AP_IF)
wlan.active(False)
print("NETWORK: Access Point disabled.") | python | {
"resource": ""
} |
q18703 | HomieNode.get_property_id_from_set_topic | train | def get_property_id_from_set_topic(self, topic):
"""Return the property id from topic as integer"""
topic = topic.decode()
return int(topic.split("/")[-3].split("_")[-1]) | python | {
"resource": ""
} |
q18704 | HomieDevice.add_node | train | def add_node(self, node):
"""add a node class of HomieNode to this device"""
self.nodes.append(node)
# add node_ids
try:
if node.node_id != b"$stats":
self.node_ids.append(node.node_id)
except NotImplementedError:
raise
except Exce... | python | {
"resource": ""
} |
q18705 | HomieDevice.subscribe_topics | train | def subscribe_topics(self):
"""subscribe to all registered device and node topics"""
base = self.topic
subscribe = self.mqtt.subscribe
# device topics
subscribe(b"/".join((base, b"$stats/interval/set")))
subscribe(b"/".join((self.settings.MQTT_BASE_TOPIC, b"$broadcast/#"... | python | {
"resource": ""
} |
q18706 | HomieDevice.publish_properties | train | def publish_properties(self):
"""publish device and node properties"""
publish = self.publish
# device properties
publish(b"$homie", b"3.0.1")
publish(b"$name", self.settings.DEVICE_NAME)
publish(b"$state", b"init")
publish(b"$fw/name", b"Microhomie")
pub... | python | {
"resource": ""
} |
q18707 | HomieDevice.publish_data | train | def publish_data(self):
"""publish node data if node has updates"""
self.publish_device_stats()
publish = self.publish
# node data
for node in self.nodes:
try:
if node.has_update():
for data in node.get_data():
... | python | {
"resource": ""
} |
q18708 | HomieDevice.start | train | def start(self):
"""publish device and node properties, run forever"""
self.publish_properties()
self.subscribe_topics()
gc.collect()
self.set_state("ready")
while True:
try:
if not utils.wlan.isconnected():
utils.wifi_con... | python | {
"resource": ""
} |
q18709 | array | train | def array(shape, dtype=_np.float64, autolock=False):
"""Factory method for shared memory arrays supporting all numpy dtypes."""
assert _NP_AVAILABLE, "To use the shared array object, numpy must be available!"
if not isinstance(dtype, _np.dtype):
dtype = _np.dtype(dtype)
# Not bothering to transl... | python | {
"resource": ""
} |
q18710 | Parallel.print | train | def print(cls, *args, **kwargs):
"""Print synchronized."""
# pylint: disable=protected-access
with _shared._PRINT_LOCK:
print(*args, **kwargs)
_sys.stdout.flush() | python | {
"resource": ""
} |
q18711 | Parallel.range | train | def range(self, start, stop=None, step=1):
"""
Get the correctly distributed parallel chunks.
This corresponds to using the OpenMP 'static' schedule.
"""
self._assert_active()
if stop is None:
start, stop = 0, start
full_list = range(start, stop, step... | python | {
"resource": ""
} |
q18712 | Parallel.xrange | train | def xrange(self, start, stop=None, step=1):
"""
Get an iterator for this threads chunk of work.
This corresponds to using the OpenMP 'dynamic' schedule.
"""
self._assert_active()
if stop is None:
start, stop = 0, start
with self._queuelock:
... | python | {
"resource": ""
} |
q18713 | Parallel.iterate | train | def iterate(self, iterable, element_timeout=None):
"""
Iterate over an iterable.
The iterator is executed in the host thread. The threads dynamically
grab the elements. The iterator elements must hence be picklable to
be transferred through the queue.
If there is only o... | python | {
"resource": ""
} |
q18714 | configure | train | def configure():
"""
Configure information about Databricks account and default behavior.
Configuration is stored in a `.apparatecfg` file. A config file must exist
before this package can be used, and can be supplied either directly as a
text file or generated using this configuration tool.
... | python | {
"resource": ""
} |
q18715 | load_library | train | def load_library(filename, match, folder, token, host):
"""
upload an egg to the Databricks filesystem.
Parameters
----------
filename: string
local location of file to upload
match: FilenameMatch object
match object with library_type, library_name, and version
folder: strin... | python | {
"resource": ""
} |
q18716 | get_job_list | train | def get_job_list(logger, match, library_mapping, token, host):
"""
get a list of jobs using the major version of the given library
Parameters
----------
logger: logging object
configured in cli_commands.py
match: FilenameMatch object
match object with suffix
library_mapping:... | python | {
"resource": ""
} |
q18717 | get_library_mapping | train | def get_library_mapping(logger, prod_folder, token, host):
"""
returns a pair of library mappings, the first mapping library uri to a
library name for all libraries in the production folder, and the second
mapping library name to info for libraries in the production folder with
parsable versions
... | python | {
"resource": ""
} |
q18718 | update_job_libraries | train | def update_job_libraries(
logger,
job_list,
match,
new_library_path,
token,
host,
):
"""
update libraries on jobs using same major version
Parameters
----------
logger: logging object
configured in cli_commands.py
job_list: list of strings
output of get_j... | python | {
"resource": ""
} |
q18719 | FileNameMatch.replace_version | train | def replace_version(self, other, logger):
"""
True if self can safely replace other
based on version numbers only - snapshot and branch tags are ignored
"""
if other.library_name != self.library_name:
logger.debug(
'not replacable: {} != {} ()'
... | python | {
"resource": ""
} |
q18720 | _resolve_input | train | def _resolve_input(variable, variable_name, config_key, config):
"""
Resolve input entered as option values with config values
If option values are provided (passed in as `variable`), then they are
returned unchanged. If `variable` is None, then we first look for a config
value to use.
If no ... | python | {
"resource": ""
} |
q18721 | upload | train | def upload(path, token, folder):
"""
The egg that the provided path points to will be uploaded to Databricks.
"""
config = _load_config(CFG_FILE)
token = _resolve_input(token, 'token', 'token', config)
folder = _resolve_input(folder, 'folder', 'prod_folder', config)
update_databricks(
... | python | {
"resource": ""
} |
q18722 | upload_and_update | train | def upload_and_update(path, token, cleanup):
"""
The egg that the provided path points to will be uploaded to Databricks.
All jobs which use the same major version of the library will be updated
to use the new version, and all version of this library in the production
folder with the same major v... | python | {
"resource": ""
} |
q18723 | parse_sas_token | train | def parse_sas_token(sas_token):
"""Parse a SAS token into its components.
:param sas_token: The SAS token.
:type sas_token: str
:rtype: dict[str, str]
"""
sas_data = {}
token = sas_token.partition(' ')[2]
fields = token.split('&')
for field in fields:
key, value = field.spli... | python | {
"resource": ""
} |
q18724 | EventData.offset | train | def offset(self):
"""
The offset of the event data object.
:rtype: ~azure.eventhub.common.Offset
"""
try:
return Offset(self._annotations[EventData.PROP_OFFSET].decode('UTF-8'))
except (KeyError, AttributeError):
return None | python | {
"resource": ""
} |
q18725 | EventData.enqueued_time | train | def enqueued_time(self):
"""
The enqueued timestamp of the event data object.
:rtype: datetime.datetime
"""
timestamp = self._annotations.get(EventData.PROP_TIMESTAMP, None)
if timestamp:
return datetime.datetime.utcfromtimestamp(float(timestamp)/1000)
... | python | {
"resource": ""
} |
q18726 | EventData.partition_key | train | def partition_key(self):
"""
The partition key of the event data object.
:rtype: bytes
"""
try:
return self._annotations[self._partition_key]
except KeyError:
return self._annotations.get(EventData.PROP_PARTITION_KEY, None) | python | {
"resource": ""
} |
q18727 | EventData.partition_key | train | def partition_key(self, value):
"""
Set the partition key of the event data object.
:param value: The partition key to set.
:type value: str or bytes
"""
annotations = dict(self._annotations)
annotations[self._partition_key] = value
header = MessageHeader... | python | {
"resource": ""
} |
q18728 | EventData.application_properties | train | def application_properties(self, value):
"""
Application defined properties on the message.
:param value: The application properties for the EventData.
:type value: dict
"""
self._app_properties = value
properties = dict(self._app_properties)
self.message... | python | {
"resource": ""
} |
q18729 | EventData.body_as_str | train | def body_as_str(self, encoding='UTF-8'):
"""
The body of the event data as a string if the data is of a
compatible type.
:param encoding: The encoding to use for decoding message data.
Default is 'UTF-8'
:rtype: str or unicode
"""
data = self.body
... | python | {
"resource": ""
} |
q18730 | EventData.body_as_json | train | def body_as_json(self, encoding='UTF-8'):
"""
The body of the event loaded as a JSON object is the data is compatible.
:param encoding: The encoding to use for decoding message data.
Default is 'UTF-8'
:rtype: dict
"""
data_str = self.body_as_str(encoding=encodi... | python | {
"resource": ""
} |
q18731 | Offset.selector | train | def selector(self):
"""
Creates a selector expression of the offset.
:rtype: bytes
"""
operator = ">=" if self.inclusive else ">"
if isinstance(self.value, datetime.datetime):
timestamp = (calendar.timegm(self.value.utctimetuple()) * 1000) + (self.value.micro... | python | {
"resource": ""
} |
q18732 | EventHubConfig.get_client_address | train | def get_client_address(self):
"""
Returns an auth token dictionary for making calls to eventhub
REST API.
:rtype: str
"""
return "amqps://{}:{}@{}.{}:5671/{}".format(
urllib.parse.quote_plus(self.policy),
urllib.parse.quote_plus(self.sas_key),
... | python | {
"resource": ""
} |
q18733 | EventHubConfig.get_rest_token | train | def get_rest_token(self):
"""
Returns an auth token for making calls to eventhub REST API.
:rtype: str
"""
uri = urllib.parse.quote_plus(
"https://{}.{}/{}".format(self.sb_name, self.namespace_suffix, self.eh_name))
sas = self.sas_key.encode('utf-8')
... | python | {
"resource": ""
} |
q18734 | Sender.send | train | def send(self, event_data):
"""
Sends an event data and blocks until acknowledgement is
received or operation times out.
:param event_data: The event to be sent.
:type event_data: ~azure.eventhub.common.EventData
:raises: ~azure.eventhub.common.EventHubError if the messa... | python | {
"resource": ""
} |
q18735 | Sender.transfer | train | def transfer(self, event_data, callback=None):
"""
Transfers an event data and notifies the callback when the operation is done.
:param event_data: The event to be sent.
:type event_data: ~azure.eventhub.common.EventData
:param callback: Callback to be run once the message has b... | python | {
"resource": ""
} |
q18736 | Sender._on_outcome | train | def _on_outcome(self, outcome, condition):
"""
Called when the outcome is received for a delivery.
:param outcome: The outcome of the message delivery - success or failure.
:type outcome: ~uamqp.constants.MessageSendResult
"""
self._outcome = outcome
self._condit... | python | {
"resource": ""
} |
q18737 | AzureStorageCheckpointLeaseManager.initialize | train | def initialize(self, host):
"""
The EventProcessorHost can't pass itself to the AzureStorageCheckpointLeaseManager
constructor because it is still being constructed. Do other initialization here
also because it might throw and hence we don't want it in the constructor.
"""
... | python | {
"resource": ""
} |
q18738 | AzureStorageCheckpointLeaseManager.get_checkpoint_async | train | async def get_checkpoint_async(self, partition_id):
"""
Get the checkpoint data associated with the given partition.
Could return null if no checkpoint has been created for that partition.
:param partition_id: The partition ID.
:type partition_id: str
:return: Given part... | python | {
"resource": ""
} |
q18739 | AzureStorageCheckpointLeaseManager.create_lease_store_if_not_exists_async | train | async def create_lease_store_if_not_exists_async(self):
"""
Create the lease store if it does not exist, do nothing if it does exist.
:return: `True` if the lease store already exists or was created successfully, `False` if not.
:rtype: bool
"""
try:
await se... | python | {
"resource": ""
} |
q18740 | AzureStorageCheckpointLeaseManager.get_lease_async | train | async def get_lease_async(self, partition_id):
"""
Return the lease info for the specified partition.
Can return null if no lease has been created in the store for the specified partition.
:param partition_id: The partition ID.
:type partition_id: str
:return: lease info... | python | {
"resource": ""
} |
q18741 | AzureStorageCheckpointLeaseManager.create_lease_if_not_exists_async | train | async def create_lease_if_not_exists_async(self, partition_id):
"""
Create in the store the lease info for the given partition, if it does not exist.
Do nothing if it does exist in the store already.
:param partition_id: The ID of a given parition.
:type partition_id: str
... | python | {
"resource": ""
} |
q18742 | AzureStorageCheckpointLeaseManager.delete_lease_async | train | async def delete_lease_async(self, lease):
"""
Delete the lease info for the given partition from the store.
If there is no stored lease for the given partition, that is treated as success.
:param lease: The stored lease to be deleted.
:type lease: ~azure.eventprocessorhost.leas... | python | {
"resource": ""
} |
q18743 | AzureStorageCheckpointLeaseManager.acquire_lease_async | train | async def acquire_lease_async(self, lease):
"""
Acquire the lease on the desired partition for this EventProcessorHost.
Note that it is legal to acquire a lease that is already owned by another host.
Lease-stealing is how partitions are redistributed when additional hosts are started.
... | python | {
"resource": ""
} |
q18744 | AzureStorageCheckpointLeaseManager.release_lease_async | train | async def release_lease_async(self, lease):
"""
Give up a lease currently held by this host. If the lease has been stolen, or expired,
releasing it is unnecessary, and will fail if attempted.
:param lease: The stored lease to be released.
:type lease: ~azure.eventprocessorhost.l... | python | {
"resource": ""
} |
q18745 | AzureStorageCheckpointLeaseManager.update_lease_async | train | async def update_lease_async(self, lease):
"""
Update the store with the information in the provided lease. It is necessary to currently
hold a lease in order to update it. If the lease has been stolen, or expired, or released,
it cannot be updated. Updating should renew the lease before... | python | {
"resource": ""
} |
q18746 | EventHubClient.from_sas_token | train | def from_sas_token(cls, address, sas_token, eventhub=None, **kwargs):
"""Create an EventHubClient from an existing auth token or token generator.
:param address: The Event Hub address URL
:type address: str
:param sas_token: A SAS token or function that returns a SAS token. If a functio... | python | {
"resource": ""
} |
q18747 | EventHubClient.from_connection_string | train | def from_connection_string(cls, conn_str, eventhub=None, **kwargs):
"""Create an EventHubClient from a connection string.
:param conn_str: The connection string.
:type conn_str: str
:param eventhub: The name of the EventHub, if the EntityName is
not included in the connection s... | python | {
"resource": ""
} |
q18748 | EventHubClient.from_iothub_connection_string | train | def from_iothub_connection_string(cls, conn_str, **kwargs):
"""
Create an EventHubClient from an IoTHub connection string.
:param conn_str: The connection string.
:type conn_str: str
:param debug: Whether to output network trace logs to the logger. Default
is `False`.
... | python | {
"resource": ""
} |
q18749 | EventHubClient.create_properties | train | def create_properties(self): # pylint: disable=no-self-use
"""
Format the properties with which to instantiate the connection.
This acts like a user agent over HTTP.
:rtype: dict
"""
properties = {}
properties["product"] = "eventhub.python"
properties["v... | python | {
"resource": ""
} |
q18750 | EventHubClient.add_receiver | train | def add_receiver(
self, consumer_group, partition, offset=None, prefetch=300,
operation=None, keep_alive=30, auto_reconnect=True):
"""
Add a receiver to the client for a particular consumer group and partition.
:param consumer_group: The name of the consumer group.
... | python | {
"resource": ""
} |
q18751 | EventHubClient.add_sender | train | def add_sender(self, partition=None, operation=None, send_timeout=60, keep_alive=30, auto_reconnect=True):
"""
Add a sender to the client to EventData object to an EventHub.
:param partition: Optionally specify a particular partition to send to.
If omitted, the events will be distribut... | python | {
"resource": ""
} |
q18752 | EventHubClientAsync._create_auth | train | def _create_auth(self, username=None, password=None):
"""
Create an ~uamqp.authentication.cbs_auth_async.SASTokenAuthAsync instance to authenticate
the session.
:param username: The name of the shared access policy.
:type username: str
:param password: The shared access ... | python | {
"resource": ""
} |
q18753 | EventHubClientAsync.get_eventhub_info_async | train | async def get_eventhub_info_async(self):
"""
Get details on the specified EventHub async.
:rtype: dict
"""
alt_creds = {
"username": self._auth_config.get("iot_username"),
"password":self._auth_config.get("iot_password")}
try:
mgmt_aut... | python | {
"resource": ""
} |
q18754 | EventHubClientAsync.add_async_receiver | train | def add_async_receiver(
self, consumer_group, partition, offset=None, prefetch=300,
operation=None, keep_alive=30, auto_reconnect=True, loop=None):
"""
Add an async receiver to the client for a particular consumer group and partition.
:param consumer_group: The name of t... | python | {
"resource": ""
} |
q18755 | Checkpoint.from_source | train | def from_source(self, checkpoint):
"""
Creates a new Checkpoint from an existing checkpoint.
:param checkpoint: Existing checkpoint.
:type checkpoint: ~azure.eventprocessorhost.checkpoint.Checkpoint
"""
self.partition_id = checkpoint.partition_id
self.offset = ch... | python | {
"resource": ""
} |
q18756 | AzureBlobLease.with_blob | train | def with_blob(self, blob):
"""
Init Azure Blob Lease with existing blob.
"""
content = json.loads(blob.content)
self.partition_id = content["partition_id"]
self.owner = content["owner"]
self.token = content["token"]
self.epoch = content["epoch"]
se... | python | {
"resource": ""
} |
q18757 | AzureBlobLease.with_source | train | def with_source(self, lease):
"""
Init Azure Blob Lease from existing.
"""
super().with_source(lease)
self.offset = lease.offset
self.sequence_number = lease.sequence_number | python | {
"resource": ""
} |
q18758 | AzureBlobLease.is_expired | train | async def is_expired(self):
"""
Check and return Azure Blob Lease state using Storage API.
"""
if asyncio.iscoroutinefunction(self.state):
current_state = await self.state()
else:
current_state = self.state()
if current_state:
return cu... | python | {
"resource": ""
} |
q18759 | PartitionPump.run | train | def run(self):
"""
Makes pump sync so that it can be run in a thread.
"""
self.loop = asyncio.new_event_loop()
self.loop.run_until_complete(self.open_async()) | python | {
"resource": ""
} |
q18760 | PartitionPump.set_pump_status | train | def set_pump_status(self, status):
"""
Updates pump status and logs update to console.
"""
self.pump_status = status
_logger.info("%r partition %r", status, self.lease.partition_id) | python | {
"resource": ""
} |
q18761 | PartitionPump.set_lease | train | def set_lease(self, new_lease):
"""
Sets a new partition lease to be processed by the pump.
:param lease: The lease to set.
:type lease: ~azure.eventprocessorhost.lease.Lease
"""
if self.partition_context:
self.partition_context.lease = new_lease
... | python | {
"resource": ""
} |
q18762 | PartitionPump.open_async | train | async def open_async(self):
"""
Opens partition pump.
"""
self.set_pump_status("Opening")
self.partition_context = PartitionContext(self.host, self.lease.partition_id,
self.host.eh_config.client_address,
... | python | {
"resource": ""
} |
q18763 | PartitionPump.close_async | train | async def close_async(self, reason):
"""
Safely closes the pump.
:param reason: The reason for the shutdown.
:type reason: str
"""
self.set_pump_status("Closing")
try:
await self.on_closing_async(reason)
if self.processor:
... | python | {
"resource": ""
} |
q18764 | PartitionPump.process_events_async | train | async def process_events_async(self, events):
"""
Process pump events.
:param events: List of events to be processed.
:type events: list[~azure.eventhub.common.EventData]
"""
if events:
# Synchronize to serialize calls to the processor. The handler is not ins... | python | {
"resource": ""
} |
q18765 | EventHubPartitionPump.on_open_async | train | async def on_open_async(self):
"""
Eventhub Override for on_open_async.
"""
_opened_ok = False
_retry_count = 0
while (not _opened_ok) and (_retry_count < 5):
try:
await self.open_clients_async()
_opened_ok = True
ex... | python | {
"resource": ""
} |
q18766 | EventHubPartitionPump.open_clients_async | train | async def open_clients_async(self):
"""
Responsible for establishing connection to event hub client
throws EventHubsException, IOException, InterruptedException, ExecutionException.
"""
await self.partition_context.get_initial_offset_async()
# Create event hub client and ... | python | {
"resource": ""
} |
q18767 | EventHubPartitionPump.clean_up_clients_async | train | async def clean_up_clients_async(self):
"""
Resets the pump swallows all exceptions.
"""
if self.partition_receiver:
if self.eh_client:
await self.eh_client.stop_async()
self.partition_receiver = None
self.partition_receive_hand... | python | {
"resource": ""
} |
q18768 | EventHubPartitionPump.on_closing_async | train | async def on_closing_async(self, reason):
"""
Overides partition pump on closing.
:param reason: The reason for the shutdown.
:type reason: str
"""
self.partition_receiver.eh_partition_pump.set_pump_status("Errored")
try:
await self.running
ex... | python | {
"resource": ""
} |
q18769 | PartitionReceiver.run | train | async def run(self):
"""
Runs the async partion reciever event loop to retrive messages from the event queue.
"""
# Implement pull max batch from queue instead of one message at a time
while self.eh_partition_pump.pump_status != "Errored" and not self.eh_partition_pump.is_closing... | python | {
"resource": ""
} |
q18770 | Lease.with_partition_id | train | def with_partition_id(self, partition_id):
"""
Init with partition Id.
:param partition_id: ID of a given partition.
:type partition_id: str
"""
self.partition_id = partition_id
self.owner = None
self.token = None
self.epoch = 0
self.event... | python | {
"resource": ""
} |
q18771 | Lease.with_source | train | def with_source(self, lease):
"""
Init with existing lease.
:param lease: An existing Lease.
:type lease: ~azure.eventprocessorhost.lease.Lease
"""
self.partition_id = lease.partition_id
self.epoch = lease.epoch
self.owner = lease.owner
self.token... | python | {
"resource": ""
} |
q18772 | EventProcessorHost.open_async | train | async def open_async(self):
"""
Starts the host.
"""
if not self.loop:
self.loop = asyncio.get_event_loop()
await self.partition_manager.start_async() | python | {
"resource": ""
} |
q18773 | PartitionContext.set_offset_and_sequence_number | train | def set_offset_and_sequence_number(self, event_data):
"""
Updates offset based on event.
:param event_data: A received EventData with valid offset and sequenceNumber.
:type event_data: ~azure.eventhub.common.EventData
"""
if not event_data:
raise Exception(ev... | python | {
"resource": ""
} |
q18774 | PartitionContext.get_initial_offset_async | train | async def get_initial_offset_async(self): # throws InterruptedException, ExecutionException
"""
Gets the initial offset for processing the partition.
:rtype: str
"""
_logger.info("Calling user-provided initial offset provider %r %r",
self.host.guid, self.par... | python | {
"resource": ""
} |
q18775 | PartitionContext.checkpoint_async | train | async def checkpoint_async(self, event_processor_context=None):
"""
Generates a checkpoint for the partition using the curren offset and sequenceNumber for
and persists to the checkpoint manager.
:param event_processor_context An optional custom state value for the Event Processor.
... | python | {
"resource": ""
} |
q18776 | PartitionContext.checkpoint_async_event_data | train | async def checkpoint_async_event_data(self, event_data, event_processor_context=None):
"""
Stores the offset and sequenceNumber from the provided received EventData instance,
then writes those values to the checkpoint store via the checkpoint manager.
Optionally stores the state of the E... | python | {
"resource": ""
} |
q18777 | PartitionContext.persist_checkpoint_async | train | async def persist_checkpoint_async(self, checkpoint, event_processor_context=None):
"""
Persists the checkpoint, and - optionally - the state of the Event Processor.
:param checkpoint: The checkpoint to persist.
:type checkpoint: ~azure.eventprocessorhost.checkpoint.Checkpoint
:... | python | {
"resource": ""
} |
q18778 | Receiver.receive | train | def receive(self, max_batch_size=None, timeout=None):
"""
Receive events from the EventHub.
:param max_batch_size: Receive a batch of events. Batch size will
be up to the maximum specified, but will return as soon as service
returns no new events. If combined with a timeout an... | python | {
"resource": ""
} |
q18779 | PartitionManager.get_partition_ids_async | train | async def get_partition_ids_async(self):
"""
Returns a list of all the event hub partition IDs.
:rtype: list[str]
"""
if not self.partition_ids:
try:
eh_client = EventHubClientAsync(
self.host.eh_config.client_address,
... | python | {
"resource": ""
} |
q18780 | PartitionManager.start_async | train | async def start_async(self):
"""
Intializes the partition checkpoint and lease store and then calls run async.
"""
if self.run_task:
raise Exception("A PartitionManager cannot be started multiple times.")
partition_count = await self.initialize_stores_async()
... | python | {
"resource": ""
} |
q18781 | PartitionManager.stop_async | train | async def stop_async(self):
"""
Terminiates the partition manger.
"""
self.cancellation_token.cancel()
if self.run_task and not self.run_task.done():
await self.run_task | python | {
"resource": ""
} |
q18782 | PartitionManager.run_async | train | async def run_async(self):
"""
Starts the run loop and manages exceptions and cleanup.
"""
try:
await self.run_loop_async()
except Exception as err: # pylint: disable=broad-except
_logger.error("Run loop failed %r", err)
try:
_logger.... | python | {
"resource": ""
} |
q18783 | PartitionManager.initialize_stores_async | train | async def initialize_stores_async(self):
"""
Intializes the partition checkpoint and lease store ensures that a checkpoint
exists for all partitions. Note in this case checkpoint and lease stores are
the same storage manager construct.
:return: Returns the number of partitions.
... | python | {
"resource": ""
} |
q18784 | PartitionManager.retry_async | train | async def retry_async(self, func, partition_id, retry_message,
final_failure_message, max_retries, host_id):
"""
Throws if it runs out of retries. If it returns, action succeeded.
"""
created_okay = False
retry_count = 0
while not created_okay an... | python | {
"resource": ""
} |
q18785 | PartitionManager.run_loop_async | train | async def run_loop_async(self):
"""
This is the main execution loop for allocating and manging pumps.
"""
while not self.cancellation_token.is_cancelled:
lease_manager = self.host.storage_manager
# Inspect all leases.
# Acquire any expired leases.
... | python | {
"resource": ""
} |
q18786 | PartitionManager.check_and_add_pump_async | train | async def check_and_add_pump_async(self, partition_id, lease):
"""
Updates the lease on an exisiting pump.
:param partition_id: The partition ID.
:type partition_id: str
:param lease: The lease to be used.
:type lease: ~azure.eventprocessorhost.lease.Lease
"""
... | python | {
"resource": ""
} |
q18787 | PartitionManager.create_new_pump_async | train | async def create_new_pump_async(self, partition_id, lease):
"""
Create a new pump thread with a given lease.
:param partition_id: The partition ID.
:type partition_id: str
:param lease: The lease to be used.
:type lease: ~azure.eventprocessorhost.lease.Lease
"""
... | python | {
"resource": ""
} |
q18788 | PartitionManager.remove_pump_async | train | async def remove_pump_async(self, partition_id, reason):
"""
Stops a single partiton pump.
:param partition_id: The partition ID.
:type partition_id: str
:param reason: A reason for closing.
:type reason: str
"""
if partition_id in self.partition_pumps:
... | python | {
"resource": ""
} |
q18789 | PartitionManager.which_lease_to_steal | train | def which_lease_to_steal(self, stealable_leases, have_lease_count):
"""
Determines and return which lease to steal
If the number of leases is a multiple of the number of hosts, then the desired
configuration is that all hosts own the name number of leases, and the
difference betw... | python | {
"resource": ""
} |
q18790 | PartitionManager.count_leases_by_owner | train | def count_leases_by_owner(self, leases): # pylint: disable=no-self-use
"""
Returns a dictionary of leases by current owner.
"""
owners = [l.owner for l in leases]
return dict(Counter(owners)) | python | {
"resource": ""
} |
q18791 | PartitionManager.attempt_renew_lease_async | train | async def attempt_renew_lease_async(self, lease_task, owned_by_others_q, lease_manager):
"""
Attempts to renew a potential lease if possible and
marks in the queue as none adds to adds to the queue.
"""
try:
possible_lease = await lease_task
if await possi... | python | {
"resource": ""
} |
q18792 | PymataSocket.start | train | async def start(self):
"""
This method opens an IP connection on the IP device
:return: None
"""
try:
self.reader, self.writer = await asyncio.open_connection(
self.ip_address, self.port, loop=self.loop)
except OSError:
print("Can'... | python | {
"resource": ""
} |
q18793 | PyMata3.digital_read | train | def digital_read(self, pin):
"""
Retrieve the last data update for the specified digital pin.
It is intended for a polling application.
:param pin: Digital pin number
:returns: Last value reported for the digital pin
"""
task = asyncio.ensure_future(self.core.di... | python | {
"resource": ""
} |
q18794 | PyMata3.encoder_read | train | def encoder_read(self, pin):
"""
This method retrieves the latest encoder data value.
It is a FirmataPlus feature.
:param pin: Encoder Pin
:returns: encoder data value
"""
try:
task = asyncio.ensure_future(self.core.encoder_read(pin))
val... | python | {
"resource": ""
} |
q18795 | PyMata3.enable_digital_reporting | train | def enable_digital_reporting(self, pin):
"""
Enables digital reporting. By turning reporting on for all
8 bits in the "port".
This is part of Firmata's protocol specification.
:param pin: Pin and all pins for this port
:returns: No return value
"""
task ... | python | {
"resource": ""
} |
q18796 | PyMata3.extended_analog | train | def extended_analog(self, pin, data):
"""
This method will send an extended-data analog write command
to the selected pin..
:param pin: 0 - 127
:param data: 0 - 0-0x4000 (14 bits)
:returns: No return value
"""
task = asyncio.ensure_future(self.core.exte... | python | {
"resource": ""
} |
q18797 | PyMata3.get_analog_map | train | def get_analog_map(self, cb=None):
"""
This method requests and returns an analog map.
:param cb: Optional callback reference
:returns: An analog map response or None if a timeout occurs
"""
task = asyncio.ensure_future(self.core.get_analog_map())
report = self.... | python | {
"resource": ""
} |
q18798 | PyMata3.get_capability_report | train | def get_capability_report(self, raw=True, cb=None):
"""
This method retrieves the Firmata capability report
:param raw: If True, it either stores or provides the callback
with a report as list.
If False, prints a formatted report to the console
:... | python | {
"resource": ""
} |
q18799 | PyMata3.get_pymata_version | train | def get_pymata_version(self):
"""
This method retrieves the PyMata version number
:returns: PyMata version number.
"""
task = asyncio.ensure_future(self.core.get_pymata_version())
self.loop.run_until_complete(task) | python | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.