Let's take this Python script, timer.py:
from time import clock
import threading
def sleep(num, func, test, args):
fire = clock() + num
while clock() < fire:
if not test():
return
func(*args)
def balance(num, func, test, args = [], tar = sleep):
t = threading.Thread(target = tar, kwargs = locals())
t.start()
and a plugin:
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Thursday, July 21, 2005, 9:57 PM -->
<!-- MuClient version 3.66 -->
<muclient>
<plugin
name="Bazzinator"
author="mudguy"
id="bd3b5b5ec7994dc41dfbd2ca"
language="Python"
purpose="To bazzinate the foobar"
save_state="y"
date_written="2005-07-21 21:57:00"
requires="3.66"
>
</plugin>
<!-- Get our standard constants -->
<include name="constants.pys"/>
<!-- Script -->
<script>
<![CDATA[
import timer
def foo():
timer.balance(10, baz, bar)
def bar():
return True
def baz():
world.Note('Done!')
]]>
</script>
</muclient>
Now, when I run this, it chugs along fine for the 10 seconds while the thread runs, but as soon as it calls baz Windows tells me that MUSHclient 'has run into problems and must be shut down'. This is decidedly weird, since with the send details box open, I can still input commands to MUSHclient and receive lines from the server back. If someone tells me how to extract the information provided by this dialogue box (some DLLs referenced and a hex dump, I think), I can provide that as well, but as it is now I can only look at it and not copy it. This is on XP Professional, SP 2, with MUSHclient 3.66.
I know this can be done with MUSHclient timers instead, but I'm planning to expand this to things that can't be done with those.
So what am I doing wrong? Or how can I work around this problem? |