Skip to content

Commit 8e289c6

Browse files
authored
Merge pull request #775 from ixcat/issue-668
datajoint/admin.py: add order_by argument to dj.kill (#668)
2 parents 98c0a81 + 0e4c800 commit 8e289c6

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

datajoint/admin.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ def set_password(new_password=None, connection=None, update_config=None): # pr
2121
config.save_local(verbose=True)
2222

2323

24-
def kill(restriction=None, connection=None): # pragma: no cover
24+
def kill(restriction=None, connection=None, order_by=None): # pragma: no cover
2525
"""
2626
view and kill database connections.
2727
:param restriction: restriction to be applied to processlist
2828
:param connection: a datajoint.Connection object. Default calls datajoint.conn()
29+
:param order_by: order by string clause for output ordering. defaults to 'id'.
2930
3031
Restrictions are specified as strings and can involve any of the attributes of
3132
information_schema.processlist: ID, USER, HOST, DB, COMMAND, TIME, STATE, INFO.
@@ -39,7 +40,8 @@ def kill(restriction=None, connection=None): # pragma: no cover
3940
connection = conn()
4041

4142
query = 'SELECT * FROM information_schema.processlist WHERE id <> CONNECTION_ID()' + (
42-
"" if restriction is None else ' AND (%s)' % restriction)
43+
"" if restriction is None else ' AND (%s)' % restriction) + (
44+
' ORDER BY %s' % (order_by or 'id'))
4345

4446
while True:
4547
print(' ID USER HOST STATE TIME INFO')
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
For example, to sort the output by hostname in descending order:
3+
4+
.. code-block:: text
5+
6+
In [3]: dj.kill(None, None, 'host desc')
7+
Out[3]:
8+
ID USER HOST STATE TIME INFO
9+
+--+ +----------+ +-----------+ +-----------+ +-----+
10+
33 chris localhost:54840 1261 None
11+
17 chris localhost:54587 3246 None
12+
4 event_scheduler localhost Waiting on empty queue 187180 None
13+
process to kill or "q" to quit > q
14+

0 commit comments

Comments
 (0)