• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

datajoint / datajoint-python / #12868

pending completion
#12868

push

travis-ci

web-flow
<a href="https://github.com/datajoint/datajoint-python/commit/<a class=hub.com/datajoint/datajoint-python/commit/<a class="double-link" href="https://git"><a class=hub.com/datajoint/datajoint-python/commit/<a class="double-link" href="https://git"><a class=hub.com/datajoint/datajoint-python/commit/555c2b6bdb9d08610421002657528ac5a3e2b7f7">555c2b6bd<a href="https://github.com/datajoint/datajoint-python/commit/555c2b6bdb9d08610421002657528ac5a3e2b7f7">&quot;&gt;&amp;lt;a href=&amp;quot;https://github.com/datajoint/datajoint-python/commit/&lt;/a&gt;&lt;a class=&quot;double-link&quot; href=&quot;https://github.com/datajoint/datajoint-python/commit/&amp;lt;a class=&amp;quot;double-link&amp;quot; href=&amp;quot;https://git&quot;&gt;&amp;lt;a class=&lt;/a&gt;hub.com/datajoint/datajoint-python/commit/555c2b6bdb9d08610421002657528ac5a3e2b7f7&quot;&gt;555c2b6bd&lt;/a&gt;&lt;a href=&quot;https://github.com/datajoint/datajoint-python/commit/555c2b6bdb9d08610421002657528ac5a3e2b7f7&quot;&gt;&amp;lt;a href=&amp;quot;https://github.com/datajoint/datajoint-python/commit/555c2b6bdb9d08610421002657528ac5&lt;/a&gt;a3e2b7f7&quot;>&quot;&gt;Merge &lt;/a&gt;&lt;a class=&quot;double-link&quot; href=&quot;https://github.com/datajoint/datajoint-python/commit/&lt;a class=&quot;double-link&quot; href=&quot;https://github.com/datajoint/datajoint-python/commit/<a class="double-link" href="https://github.com/datajoint/datajoint-python/commit/94804352b336cfb4c047ecd4e687c9643a7b3e47">94804352b</a><a href="https://github.com/datajoint/datajoint-python/commit/555c2b6bdb9d08610421002657528ac5a3e2b7f7">&amp;quot;&amp;gt;94804352b&amp;lt;/a&amp;gt;&amp;quot;&amp;gt;94804352b&amp;lt;/a&amp;gt;&amp;lt;a href=&amp;quot;https://github.com/datajoint/datajoint-python/commit/555c2b6bdb9d08610421002657528ac5a3e2b&lt;/a&gt;7f7&quot;&gt; into &lt;/a&gt;&lt;a class=&quot;double-link&quot; href=&quot;https://github.com/datajoint/datajoint-python/commit/<a class="double-link" href="https://github.com/datajoint/datajoint-python/commit/e339d465f">e339d465f">e339d465f</a>

29 of 29 new or added lines in 1 file covered. (100.0%)

3036 of 3358 relevant lines covered (90.41%)

0.9 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

40.0
/datajoint/admin.py
1
import pymysql
1✔
2
from getpass import getpass
1✔
3
from .connection import conn
1✔
4
from .settings import config
1✔
5
from .utils import user_choice
1✔
6

7

8
def set_password(
9
    new_password=None, connection=None, update_config=None
10
):  # pragma: no cover
11
    connection = conn() if connection is None else connection
12
    if new_password is None:
13
        new_password = getpass("New password: ")
14
        confirm_password = getpass("Confirm password: ")
15
        if new_password != confirm_password:
16
            print("Failed to confirm the password! Aborting password change.")
17
            return
18
    connection.query("SET PASSWORD = PASSWORD('%s')" % new_password)
19
    print("Password updated.")
20

21
    if update_config or (
22
        update_config is None and user_choice("Update local setting?") == "yes"
23
    ):
24
        config["database.password"] = new_password
25
        config.save_local(verbose=True)
26

27

28
def kill(restriction=None, connection=None, order_by=None):  # pragma: no cover
29
    """
30
    view and kill database connections.
31

32
    :param restriction: restriction to be applied to processlist
33
    :param connection: a datajoint.Connection object. Default calls datajoint.conn()
34
    :param order_by: order by a single attribute or the list of attributes. defaults to 'id'.
35

36
    Restrictions are specified as strings and can involve any of the attributes of
37
    information_schema.processlist: ID, USER, HOST, DB, COMMAND, TIME, STATE, INFO.
38

39
    Examples:
40
        dj.kill('HOST LIKE "%compute%"') lists only connections from hosts containing "compute".
41
        dj.kill('TIME > 600') lists only connections in their current state for more than 10 minutes
42
    """
43

44
    if connection is None:
45
        connection = conn()
46

47
    if order_by is not None and not isinstance(order_by, str):
48
        order_by = ",".join(order_by)
49

50
    query = (
51
        "SELECT * FROM information_schema.processlist WHERE id <> CONNECTION_ID()"
52
        + ("" if restriction is None else " AND (%s)" % restriction)
53
        + (" ORDER BY %s" % (order_by or "id"))
54
    )
55

56
    while True:
57
        print("  ID USER         HOST          STATE         TIME    INFO")
58
        print("+--+ +----------+ +-----------+ +-----------+ +-----+")
59
        cur = (
60
            {k.lower(): v for k, v in elem.items()}
61
            for elem in connection.query(query, as_dict=True)
62
        )
63
        for process in cur:
64
            try:
65
                print(
66
                    "{id:>4d} {user:<12s} {host:<12s} {state:<12s} {time:>7d}  {info}".format(
67
                        **process
68
                    )
69
                )
70
            except TypeError:
71
                print(process)
72
        response = input('process to kill or "q" to quit > ')
73
        if response == "q":
74
            break
75
        if response:
76
            try:
77
                pid = int(response)
78
            except ValueError:
79
                pass  # ignore non-numeric input
80
            else:
81
                try:
82
                    connection.query("kill %d" % pid)
83
                except pymysql.err.InternalError:
84
                    print("Process not found")
85

86

87
def kill_quick(restriction=None, connection=None):
1✔
88
    """
89
    Kill database connections without prompting. Returns number of terminated connections.
90

91
    :param restriction: restriction to be applied to processlist
92
    :param connection: a datajoint.Connection object. Default calls datajoint.conn()
93

94
    Restrictions are specified as strings and can involve any of the attributes of
95
    information_schema.processlist: ID, USER, HOST, DB, COMMAND, TIME, STATE, INFO.
96

97
    Examples:
98
        dj.kill('HOST LIKE "%compute%"') terminates connections from hosts containing "compute".
99
    """
100
    if connection is None:
×
101
        connection = conn()
×
102

103
    query = (
×
104
        "SELECT * FROM information_schema.processlist WHERE id <> CONNECTION_ID()"
105
        + ("" if restriction is None else " AND (%s)" % restriction)
106
    )
107

108
    cur = (
×
109
        {k.lower(): v for k, v in elem.items()}
110
        for elem in connection.query(query, as_dict=True)
111
    )
112
    nkill = 0
×
113
    for process in cur:
×
114
        connection.query("kill %d" % process["id"])
×
115
        nkill += 1
×
116
    return nkill
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc