Skip to content

Commit 3be22b9

Browse files
authored
Merge pull request #377 from GoogleCloudPlatform/tswast-bigtable
Close HappyBase connection in bigtable/hello sample.
2 parents 0976714 + d9f544a commit 3be22b9

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

bigtable/hello/main.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,11 @@ def main(project_id, cluster_id, zone, table_name):
3737
# The client must be created with admin=True because it will create a
3838
# table.
3939
client = bigtable.Client(project=project_id, admin=True)
40+
cluster = client.cluster(zone, cluster_id)
41+
connection = happybase.Connection(cluster=cluster)
42+
# [END connecting_to_bigtable]
4043

41-
with client:
42-
cluster = client.cluster(zone, cluster_id)
43-
cluster.reload()
44-
connection = happybase.Connection(cluster=cluster)
45-
# [END connecting_to_bigtable]
46-
44+
try:
4745
# [START creating_a_table]
4846
print('Creating the {} table.'.format(table_name))
4947
column_family_name = 'cf1'
@@ -95,6 +93,8 @@ def main(project_id, cluster_id, zone, table_name):
9593
print('Deleting the {} table.'.format(table_name))
9694
connection.delete_table(table_name)
9795
# [END deleting_a_table]
96+
finally:
97+
connection.close()
9898

9999

100100
if __name__ == '__main__':

0 commit comments

Comments
 (0)