-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
367 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import pymysql | ||
from . import conn | ||
|
||
|
||
def kill(restriction=None, connection=None): | ||
""" | ||
view and kill database connections. | ||
:param restriction: restriciton to be applied to processlist | ||
:param connection: a datajoint.Connection object. Default calls datajoint.conn() | ||
Restrictions are specified as strings and can involve any of the attributes of | ||
information_schema.processlist: ID, USER, HOST, DB, COMMAND, TIME, STATE, INFO. | ||
Examples: | ||
dj.kill('HOST LIKE "%compute%"') lists only connections from hosts containing "compute". | ||
dj.kill('TIME > 600') lists only connections older than 10 minutes. | ||
""" | ||
|
||
if connection is None: | ||
connection = conn() | ||
|
||
query = 'SELECT * FROM information_schema.processlist WHERE id <> CONNECTION_ID()'; | ||
if restriction is not None: | ||
query += ' AND (%s)' % restriction | ||
|
||
while True: | ||
print(' ID USER STATE TIME INFO') | ||
print('+--+ +----------+ +-----------+ +--+') | ||
for process in connection.query(query, as_dict=True).fetchall(): | ||
try: | ||
print('{ID:>4d} {USER:<12s} {STATE:<12s} {TIME:>5d} {INFO}'.format(**process)) | ||
except TypeError as err: | ||
print(process) | ||
|
||
response = input('process to kill or "q" to quit)') | ||
if response == 'q': | ||
break | ||
if response: | ||
try: | ||
id = int(response) | ||
except ValueError: | ||
pass # ignore non-numeric input | ||
else: | ||
try: | ||
connection.query('kill %d' % id) | ||
except pymysql.err.InternalError: | ||
print('Process not found') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.