8000 Merge branch 'master' into upgrade-tensorflow · nyghtowl/python-docs-samples@94c42ab · GitHub
[go: up one dir, main page]

Skip to content

Commit 94c42ab

Browse files
authored
Merge branch 'master' into upgrade-tensorflow
2 parents abe3e1b + 23d8571 commit 94c42ab

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

codelabs/functions/python_powered/main.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import os
16+
1517
import flask
1618

1719

@@ -55,4 +57,4 @@ def python_powered(request):
5557
Returns:
5658
The response file, a JPG image that says "Python Powered"
5759
"""
58-
return flask.send_file("python_powered.jpg", mimetype="image/jpg")
60+
return flask.send_from_directory(os.getcwd(), "python_powered.jpg", mimetype="image/jpg")

iot/api-client/manager/manager_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,6 @@ def test_send_command(test_topic, capsys):
391391

392392
# Pre-process commands
393393
for i in range(1, 5):
394-
client.loop()
395394
time.sleep(1)
396395

397396
manager.send_command(
@@ -401,10 +400,11 @@ def test_send_command(test_topic, capsys):
401400

402401
# Process commands
403402
for i in range(1, 5):
404-
client.loop()
405403
time.sleep(1)
406404

407405
# Clean up
406+
client.loop_stop()
407+
client.disconnect()
408408
manager.delete_device(
409409
service_account_json, project_id, cloud_region, registry_id,
410410
device_id)

iot/api-client/mqtt_example/cloudiot_mqtt_example.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,8 @@ def listen_for_messages(
242242
if seconds_since_issue > 60 * jwt_exp_mins:
243243
print('Refreshing token after {}s'.format(seconds_since_issue))
244244
jwt_iat = datetime.datetime.utcnow()
245+
client.loop()
246+
client.disconnect()
245247
client = get_client(
246248
project_id, cloud_region, registry_id, gateway_id,
247249
private_key_file, algorithm, ca_certs, mqtt_bridge_hostname,
@@ -457,6 +459,8 @@ def mqtt_device_demo(args):
457459
if seconds_since_issue > 60 * jwt_exp_mins:
458460
print('Refreshing token after {}s'.format(seconds_since_issue))
459461
jwt_iat = datetime.datetime.utcnow()
462+
client.loop()
463+
client.disconnect()
460464
client = get_client(
461465
args.project_id, args.cloud_region,
462466
args.registry_id, args.device_id, args.private_key_file,
@@ -469,7 +473,9 @@ def mqtt_device_demo(args):
469473
client.publish(mqtt_topic, payload, qos=1)
470474

471475
# Send events every second. State should not be updated as often
472-
time.sleep(1 if args.message_type == 'event' else 5)
476+
for i in range(0, 60):
477+
time.sleep(1)
478+
client.loop()
473479
# [END iot_mqtt_run]
474480

475481

0 commit comments

Comments
 (0)
0