forked from daid/EmptyEpsilon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
eecs: delay lua execution, otherwise it blocks in init()
- Loading branch information
Showing
4 changed files
with
60 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
"""A worker thread, that handles all the lua exec calls asynchronously to prevent deadlocks.""" | ||
|
||
from multiprocessing import Process, Queue | ||
import time | ||
|
||
from utils import lua | ||
|
||
p = None | ||
q = Queue() | ||
|
||
def exec(script, server="127.0.0.1:8080", delay=0, callback=None, callbackArgs=[]): | ||
q.put(("exec", script, server, delay, callback, callbackArgs)) | ||
|
||
|
||
def work(q): | ||
while task := q.get(): | ||
(function, script, server, delay, callback, callbackArgs) = task | ||
if delay: | ||
time.sleep(delay) | ||
ret = None | ||
if function == "exec": | ||
ret = lua.exec(script, server) | ||
if callback: | ||
callback(*callbackArgs, ret) | ||
|
||
|
||
def start(): | ||
global p | ||
p = Process(target=work, args=(q,)) | ||
p.start() | ||
|
||
def stop(): | ||
q.put(None) | ||
p.join() |
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