diff options
author | PanFritz <redstonenoobpan@gmail.com> | 2015-08-31 03:25:37 +0200 |
---|---|---|
committer | PanFritz <redstonenoobpan@gmail.com> | 2015-08-31 03:25:37 +0200 |
commit | f711f5e46cf246a3bea1c601146c4a0b5188e06e (patch) | |
tree | fd01ac79382fe162d696e7a3b1873b32cdf81845 /helpers.py | |
parent | 465b235042858543f497ad6352c772d24b580d87 (diff) |
Added async_query since we need to remake all of our db interaction to be in a seperate thread
Diffstat (limited to 'helpers.py')
-rw-r--r-- | helpers.py | 29 |
1 files changed, 29 insertions, 0 deletions
@@ -13,6 +13,11 @@ from org.bukkit.entity import * from player import get_py_player from player import py_players +#Imports for async query +import mysqlhack +from com.ziclix.python.sql import zxJDBC +import threading + from traceback import format_exc as trace @@ -188,6 +193,30 @@ def known_player(player): """ return player.hasPlayedBefore() +""" +Runs a async query, calls target function with fetchall as an argument, it will be an empty list if there is nothing to fetch. +(So make sure your function takes that argument.) + +If you want your function to run sync in the case you are doing something spigot wouldn't like to be async use the bukkit scheduler. +Example can be found in loginsecurity.py + +""" +def async_query(mysql_database,mysql_user,mysql_pass,query,args,target): + + def async_query_t(mysql_database,mysql_user,mysql_pass,query,args,target): + db_conn = zxJDBC.connect("servercontrol.db") + db_curs = db_conn.cursor() + db_curs.execute(query,args) + db_conn.commit() + fetchall = db_curs.fetchall() + db_curs.close() + db_conn.close() + target(fetchall) + + t = threading.Thread(target=async_query_t,args=(mysql_database,mysql_user,mysql_pass,query,args,target)) + t.daemon = True + t.start() + def open_json_file(filename, default = None): """ |