Skip to content

Commit 273dfee

Browse files
author
Chris Turner
authored
Merge pull request #292 from datajoint/stage
Stage -> Master
2 parents ea1c494 + 95a1049 commit 273dfee

File tree

4 files changed

+63
-10
lines changed

4 files changed

+63
-10
lines changed

+dj/+lib/getpass.m

+8-2
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,15 @@
3535
% wait for password entry
3636
uiwait
3737
pass = get(hpass,'userdata');
38+
if isempty(pass)
39+
pass = '';
40+
end
41+
3842
% remove the figure to prevent passwork leakage
3943
delete(hfig)
40-
4144

45+
end
46+
4247
function keypress_cb(hObj, data, hpass)
4348
% Callback function to handle actual key strokes
4449

@@ -55,4 +60,5 @@ function keypress_cb(hObj, data, hpass)
5560
pass = [pass data.Character];
5661
end
5762
set(hpass, 'userdata', pass)
58-
set(hpass, 'String', char('*' * sign(pass)))
63+
set(hpass, 'String', char('*' * sign(pass)))
64+
end

+dj/conn.m

+5-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
% get password prompt option
2929
if nargin < 7 || isempty(nogui)
30-
nogui = false;
30+
nogui = ~usejava('desktop');
3131
end
3232

3333

@@ -117,4 +117,7 @@
117117

118118
if nargout==0
119119
query(connObj, 'SELECT connection_id()')
120-
end
120+
end
121+
122+
end
123+

+dj/kill.m

+36-6
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,64 @@
77
% of the attributes of information_schema.processlist: ID, USER, HOST,
88
% DB, COMMAND, TIME, STATE, INFO.
99
%
10+
% dj.kill(restriction, connection) allows specifying the target connection.
11+
% will use default connection (dj.conn) if not specified.
12+
%
13+
% dj.kill(restriction, connection, order_by) allows providing an order_by
14+
% argument. By default, output is lited by ID in ascending order.
15+
%
1016
% Examples:
1117
% dj.kill('HOST LIKE "%at-compute%"') lists only connections from
1218
% at-compute.
1319
%
1420
% dj.kill('TIME > 600') lists only connections older than 10 minutes.
21+
%
22+
% dj.kill('', dj.conn, 'time') will display no restrictions for the
23+
% default connection ordered by TIME.
24+
%
25+
26+
27+
function kill(restriction, connection, order_by)
28+
29+
if nargin < 3
30+
order_by = {};
31+
end
1532

16-
function kill(restriction)
33+
if nargin < 2
34+
connection = dj.conn;
35+
end
1736

1837
qstr = 'SELECT * FROM information_schema.processlist WHERE id <> CONNECTION_ID()';
38+
1939
if nargin && ~isempty(restriction)
2040
qstr = sprintf('%s AND (%s)', qstr, restriction);
2141
end
22-
42+
43+
if isempty(order_by)
44+
qstr = sprintf('%s ORDER BY id', qstr);
45+
else
46+
if iscell(order_by)
47+
qstr = sprintf('%s ORDER BY %s', qstr, strjoin(order_by, ','));
48+
else
49+
qstr = sprintf('%s ORDER BY %s', qstr, order_by);
50+
end
51+
end
52+
2353
while true
24-
query(dj.conn, qstr)
54+
query(connection, qstr)
2555
id = input('process to kill (''q''-quit, ''a''-all) > ', 's');
2656
if ischar(id) && strncmpi(id, 'q', 1)
2757
break
2858
elseif ischar(id) && strncmpi(id, 'a', 1)
29-
res = query(dj.conn, qstr);
59+
res = query(connection, qstr);
3060
id = double(res.ID)';
3161
for i = id
32-
query(dj.conn, 'kill {Si}', i)
62+
query(connection, 'kill {Si}', i)
3363
end
3464
break
3565
end
3666
id = sscanf(id,'%d');
3767
if ~isempty(id)
38-
query(dj.conn, 'kill {Si}', id(1))
68+
query(connection, 'kill {Si}', id(1))
3969
end
4070
end
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:: matlab
5+
6+
7+
dj.kill('', dj.conn, 'host desc');
8+
9+
ID USER HOST DB COMMAND TIME STATE INFO TIME_MS ROWS_SENT ROWS_EXAMINED
10+
+--+ +----+ +---------+ +--+ +-------+ +----+ +-----+ +----+ +-------+ +---------+ +-------------+
11+
35 cat localhost:38772 Sleep 94 94040 0 0
12+
36 cat localhost:36543 Sleep 68 68421 1 0
13+
14+
process to kill ('q'-quit, 'a'-all) > q

0 commit comments

Comments
 (0)