Cleaning up a session
If your application uses the with
keyword, the 1010ata Insights
Platform session is cleaned up automatically at the end of the with
statement. If your application does not use with
, you need to clean up the
platform session when you've completed the transaction.
The Session
class contains a Close
method, which cleans up
the session when it is invoked. Depending on the login type that was used to create the
platform session, there are a few different ways the session may be cleaned up. If you
are a single user logged in with py1010.POSSESS
, the platform session
continues to run. If you're a single user logged in with py1010.KILL
or
py1010.NOKILL
, the platform session is terminated. A SAM pool user
platform session is released back into the pool.
Cleaning up a session when it is no longer needed is particularly important if you have
multiple users sharing a pool of IDs (SAM pool). Waiting for the garbage collector to
clean up Session
objects may result in a pool that appears fully
utilized, but is waiting for Session
objects to be destroyed. For more
information about SAM pools, see Shared Access Management (SAM).
The most efficient and effective way to release user IDs back to the pool is to invoke the
close
method, either by explicitly calling it or employing
with
, which invokes it at the end of the statement.
Using the with
keyword:
import py1010 import sys gateway = "https://www2.1010data.com/cgi-bin/gw" tablename = "pub.demo.weather.stations" username = "[USER_NAME]" password = "[PASSWORD]" with py1010.Session(gateway, username, password, py1010.POSSESS) as testSession: exampleQuery = testSession.query(tablename, '<sel value="(elev>10)"/>') exampleQuery.run() for r in exampleQuery.rows: print("\t".join([str(x) for x in r]))
[USER_NAME]
and [PASSWORD]
are
placeholders for valid Insights Platform user name and password. Using the close
method:
import py1010 import sys gateway = "https://www2.1010data.com/cgi-bin/gw" tablename = "pub.demo.weather.stations" username = "[USER_NAME]" password = "[PASSWORD]" testSession = py1010.Session(gateway, username, password, py1010.POSSESS) exampleQuery = testSession.query(tablename, '<sel value="(elev>10)"/>') exampleQuery.run() for r in exampleQuery.rows: print("\t".join([str(x) for x in r])) testSession.close()
[USER_NAME]
and [PASSWORD]
are
placeholders for valid Insights Platform user name and password.