本文整理汇总了Python中storm.tracer.trace函数的典型用法代码示例。如果您正苦于以下问题:Python trace函数的具体用法?Python trace怎么用?Python trace使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了trace函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execute
def execute(self, async_conn):
"""Executes a query within an asyncronous psycopg2 connection
"""
if self.status == self.STATUS_CANCELLED:
return
self.status = self.STATUS_EXECUTING
# Async variant of Connection.execute() in storm/database.py
state = State()
statement = compile(self.expr, state)
stmt = convert_param_marks(statement, "?", "%s")
self._async_cursor = async_conn.cursor()
self._async_conn = async_conn
# This is postgres specific, see storm/databases/postgres.py
self._statement = stmt.encode('utf-8')
self._parameters = tuple(Connection.to_database(state.parameters))
trace("connection_raw_execute", self._conn,
self._async_cursor, self._statement, self._parameters)
self._async_cursor.execute(self._statement,
self._parameters)
# This can happen if another thread cancelled this while the cursor was
# executing. In that case, it is not interested in the retval anymore
if self.status == self.STATUS_CANCELLED:
return
self.status = self.STATUS_FINISHED
glib.idle_add(self._on_finish)
示例2: finish
def finish(self):
"""This can only be called when the ``finish``` signal has
been emitted.
:returns: the result, which might be an object or a list depending
on self.operation_type
"""
trace("connection_raw_execute_success", self._conn,
self._async_cursor, self._statement, self._parameters)
result = self._conn.result_factory(self._conn,
self._async_cursor)
if self.operation_type == AsyncQueryOperation.GET_ALL:
# ResultSet.__iter__()
retval = []
for values in result:
obj = self.resultset._load_objects(result, values)
retval.append(obj)
elif self.operation_type == AsyncQueryOperation.GET_ONE:
# ResultSet.one()
values = result.get_one()
retval = self.resultset._load_objects(result, values)
else:
raise NotImplementedError(self.operation_type)
return retval
示例3: commit
def commit(self, close=False):
"""Commits a database.
This needs to be done to submit the actually inserts to the database.
:param close: If ``True``, the store will also be closed after committed.
"""
self._check_obsolete()
self._committing = True
# the cache will be cleared when commiting, so store them here
# and autoreload them after commit
touched_objs = []
for obj_info in self._cache.get_cached():
obj = obj_info.get_obj()
if obj is not None:
touched_objs.append(obj)
super(StoqlibStore, self).commit()
trace('transaction_commit', self)
self._pending_count = [0]
self._savepoints = []
# Reload objects on all other opened stores
for obj in touched_objs:
autoreload_object(obj)
if close:
self.close()
self._committing = False
示例4: close
def close(self):
"""Close the store.
Closes the socket that represents that database connection, this needs to
be called when you finished using the store.
"""
trace("transaction_close", self)
self._check_obsolete()
super(StoqlibStore, self).close()
self.obsolete = True
示例5: commit
def commit(self, close=False):
"""Commits a database.
This needs to be done to submit the actually inserts to the database.
:param close: If ``True``, the store will also be closed after committed.
"""
self._check_obsolete()
self._process_pending_objs()
super(StoqlibStore, self).commit()
trace("transaction_commit", self)
if close:
self.close()
示例6: get_result
def get_result(self):
"""Get operation result.
Note that this can only be called when the *finish* signal
has been emitted.
:returns: a :class:`AsyncResultSet` containing the result
"""
assert self.status == self.STATUS_FINISHED
trace("connection_raw_execute_success", self._conn,
self._async_cursor, self._statement, self._parameters)
result = self._conn.result_factory(self._conn,
self._async_cursor)
return AsyncResultSet(self.resultset, result)
示例7: execute
def execute(self, async_conn):
"""Executes a query within an asyncronous psycopg2 connection
"""
# Async variant of Connection.execute() in storm/database.py
state = State()
statement = compile(self.expr, state)
stmt = convert_param_marks(statement, "?", "%s")
self._async_cursor = async_conn.cursor()
self._async_conn = async_conn
# This is postgres specific, see storm/databases/postgres.py
self._statement = stmt.encode("utf-8")
self._parameters = tuple(Connection.to_database(state.parameters))
trace("connection_raw_execute", self._conn, self._async_cursor, self._statement, self._parameters)
self._async_cursor.execute(self._statement, self._parameters)
示例8: __init__
def __init__(self, database=None, cache=None):
"""
Creates a new store
:param database: the database to connect to or ``None``
:param cache: storm cache to use or ``None``
"""
self._savepoints = []
self.retval = None
self.needs_retval = False
self.obsolete = False
if database is None:
database = get_default_store().get_database()
Store.__init__(self, database=database, cache=cache)
_stores.add(self)
trace('transaction_create', self)
self._reset_pending_objs()
示例9: __init__
def __init__(self, database=None, cache=None):
"""
Creates a new store
:param database: the database to connect to or ``None``
:param cache: storm cache to use or ``None``
"""
self._savepoints = []
self.retval = None
self.needs_retval = False
self.obsolete = False
if database is None:
database = get_default_store().get_database()
Store.__init__(self, database=database, cache=cache)
# FIXME: Use weakref.WeakSet when we can depend on Python 2.7
_stores[self] = None
trace("transaction_create", self)
self._reset_pending_objs()
示例10: __init__
def __init__(self, database=None, cache=None):
"""
Creates a new store
:param database: the database to connect to or ``None``
:param cache: storm cache to use or ``None``
"""
self._committing = False
self._savepoints = []
self._pending_count = [0]
self.retval = True
self.obsolete = False
if database is None:
database = get_default_store().get_database()
Store.__init__(self, database=database, cache=cache)
_stores.add(self)
trace('transaction_create', self)
self._setup_application_name()
示例11: __init__
def __init__(self, database=None, cache=None):
"""
Creates a new store
:param database: the database to connect to or ``None``
:param cache: storm cache to use or ``None``
"""
self._committing = False
self._savepoints = []
# When using savepoints, this stack will hold what objects were changed
# (created, deleted or edited) inside that savepoint.
self._dirties = [[]]
self.retval = True
self.obsolete = False
if database is None:
database = get_default_store().get_database()
Store.__init__(self, database=database, cache=cache)
_stores.add(self)
trace('transaction_create', self)
self._setup_application_name()
示例12: raw_execute
def raw_execute(self, statement, params=None):
"""Execute a raw statement with the given parameters.
It's acceptable to override this method in subclasses, but it
is not intended to be called externally.
If the global C{DEBUG} is True, the statement will be printed
to standard out.
@return: The dbapi cursor object, as fetched from L{build_raw_cursor}.
"""
raw_cursor = self.build_raw_cursor()
trace("connection_raw_execute", self, raw_cursor,
statement, params or ())
if params:
args = (statement, tuple(self.to_database(params)))
else:
args = (statement,)
try:
self._check_disconnect(raw_cursor.execute, *args)
except Exception, error:
trace("connection_raw_execute_error", self, raw_cursor,
statement, params or (), error)
raise
示例13: test_trace
def test_trace(self):
stash = []
class Tracer(object):
def m1(_, *args, **kwargs):
stash.extend(["m1", args, kwargs])
def m2(_, *args, **kwargs):
stash.extend(["m2", args, kwargs])
install_tracer(Tracer())
trace("m1", 1, 2, c=3)
trace("m2")
trace("m3")
self.assertEquals(stash, ["m1", (1, 2), {"c": 3}, "m2", (), {}])
示例14: test_capture_multiple
def test_capture_multiple(self):
"""L{CaptureTracer}s can be used as nested context managers."""
conn = StubConnection()
def trace(statement):
for tracer in get_tracers():
tracer.connection_raw_execute(conn, "cursor", statement, [])
with CaptureTracer() as tracer1:
trace("one")
with CaptureTracer() as tracer2:
trace("two")
trace("three")
self.assertEqual([], get_tracers())
self.assertEqual(["one", "two", "three"], tracer1.queries)
self.assertEqual(["two"], tracer2.queries)
示例15: trace
"""
raw_cursor = self.build_raw_cursor()
trace("connection_raw_execute", self, raw_cursor,
statement, params or ())
if params:
args = (statement, tuple(self.to_database(params)))
else:
args = (statement,)
try:
self._check_disconnect(raw_cursor.execute, *args)
except Exception, error:
trace("connection_raw_execute_error", self, raw_cursor,
statement, params or (), error)
raise
else:
trace("connection_raw_execute_success", self, raw_cursor,
statement, params or ())
return raw_cursor
def _ensure_connected(self):
"""Ensure that we are connected to the database.
If the connection is marked as dead, or if we can't reconnect,
then raise DisconnectionError.
"""
if self._state == STATE_CONNECTED:
return
elif self._state == STATE_DISCONNECTED:
raise DisconnectionError("Already disconnected")
elif self._state == STATE_RECONNECT:
try:
self._raw_connection = self._database.raw_connect()