2000Q1/
<!-- MHonArc v2.4.4 -->
<!--X-Subject: [MUD&#45;Dev] Embedding Python -->
<!--X-From-R13: vprphorNvuht.pb.am -->
<!--X-Date: Sat, 12 Feb 2000 16:10:51 &#45;0800 -->
<!--X-Message-Id: 20000212213017.K535#agrajag,internal -->
<!--X-Content-Type: text/plain -->
<!--X-Head-End-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<title>MUD-Dev message, [MUD-Dev] Embedding Python</title>
<!-- meta name="robots" content="noindex,nofollow" -->
<link rev="made" href="mailto:icecube#ihug,co.nz">
</head>
<body background="/backgrounds/paperback.gif" bgcolor="#ffffff"
      text="#000000" link="#0000FF" alink="#FF0000" vlink="#006000">

  <font size="+4" color="#804040">
    <strong><em>MUD-Dev<br>mailing list archive</em></strong>
  </font>
      
<br>
[&nbsp;<a href="../">Other Periods</a>
&nbsp;|&nbsp;<a href="../../">Other mailing lists</a>
&nbsp;|&nbsp;<a href="/search.php3">Search</a>
&nbsp;]
<br clear=all><hr>
<!--X-Body-Begin-->
<!--X-User-Header-->
<!--X-User-Header-End-->
<!--X-TopPNI-->

Date:&nbsp;
[&nbsp;<a href="msg00295.html">Previous</a>
&nbsp;|&nbsp;<a href="msg00297.html">Next</a>
&nbsp;]
&nbsp;&nbsp;&nbsp;&nbsp;
Thread:&nbsp;
[&nbsp;<a href="msg00312.html">Previous</a>
&nbsp;|&nbsp;<a href="msg00713.html">Next</a>
&nbsp;]
&nbsp;&nbsp;&nbsp;&nbsp;
Index:&nbsp;
[&nbsp;<A HREF="author.html#00296">Author</A>
&nbsp;|&nbsp;<A HREF="#00296">Date</A>
&nbsp;|&nbsp;<A HREF="thread.html#00296">Thread</A>
&nbsp;]

<!--X-TopPNI-End-->
<!--X-MsgBody-->
<!--X-Subject-Header-Begin-->
<H1>[MUD-Dev] Embedding Python</H1>
<HR>
<!--X-Subject-Header-End-->
<!--X-Head-of-Message-->
<UL>
<LI><em>To</em>: <A HREF="mailto:mud-dev#kanga,nu">mud-dev#kanga,nu</A></LI>
<LI><em>Subject</em>: [MUD-Dev] Embedding Python</LI>
<LI><em>From</em>: <A HREF="mailto:icecube#ihug,co.nz">icecube#ihug,co.nz</A></LI>
<LI><em>Date</em>: Sat, 12 Feb 2000 21:30:17 +1300</LI>
<LI><em>Mail-Followup-To</em>: mud-dev#kanga,nu</LI>
<LI><em>Reply-To</em>: <A HREF="mailto:mud-dev#kanga,nu">mud-dev#kanga,nu</A></LI>
<LI><em>Sender</em>: <A HREF="mailto:mud-dev-admin#kanga,nu">mud-dev-admin#kanga,nu</A></LI>
</UL>
<!--X-Head-of-Message-End-->
<!--X-Head-Body-Sep-Begin-->
<HR>
<!--X-Head-Body-Sep-End-->
<!--X-Body-of-Message-->
<PRE>
I'm looking at embedding Python in at least one mud, and there are a few
practical issues I've run into with the standard Python codebase. Given
that there are members of mud-dev who seem to be doing similar things, I'm
hoping I can avoid reinventing the wheel as much as possible here :) 

The basic structure I want is the core C++ code calling Python code when
events occur within the game. Python-&gt;C++ calls will be brief and
essentially limited to thread management and game object modification.

Potentially all Python threads can be long-lived, reacting to later
events. The server is single-threaded so manually suspending and resuming
the threads is needed. I'm currently looking at a model similar to the
ColdC/Genesis thread model - no preemptive thread switching, but limits on
execution time without allowing a context switch. 

I need to be able to catch runaway execution. A simple "&gt;x bytecodes
executed since last context switch" would do. It might be nice to have a
"warning" exception so intermediate levels of Python can at least tell the
user what happened while trying to do something. The Python microthreads
extensions [1] seems to allow this. 

I need to be able to suspend a thread of execution in mid-stream, either
waiting on some external event (eg. player input arriving) or to allow a
context switch. Stackless Python [2] looks like it can handle this, since
it can already handle continuations and coroutines.

Stackless Python and microthreads are apparently on the path to
integration, but they're not there yet. It looks non-trivial to do
especially without knowing the guts of the Python interpreter in detail
(which I don't). 

Garbage collection is an issue since standard Python has a simple
refcounting scheme that won't detect reference cycles. There are a couple
of solutions for this around [3] although I haven't actually tried them.

Excessive memory use may be an issue. It would be nice to be able to
"charge"  python code for memory allocation it causes, and catch runaway
allocation before Bad Things happen. I'm not sure where to begin with
this!

Anyone working along the same lines and would like to share their
insights?

-- 
Oliver Jowett - icecube#ihug,co.nz - <A  HREF="http://homepages.ihug.co.nz/~icecube/">http://homepages.ihug.co.nz/~icecube/</A>
KeyID: 1024/679D94C5  Fingerprint: CD94 5270 E2F4 339F 6A90 05C9 9DE4 EECC

[1] Python microthreads -- <A  HREF="http://world.std.com/~wware/uthread.html">http://world.std.com/~wware/uthread.html</A>
[2] Stackless Python -- <A  HREF="http://www.tismer.com/research/stackless/">http://www.tismer.com/research/stackless/</A>
[3] Python GC -- <A  HREF="http://www.acs.ucalgary.ca/~nascheme/python/gc.html">http://www.acs.ucalgary.ca/~nascheme/python/gc.html</A>



_______________________________________________
MUD-Dev maillist  -  MUD-Dev#kanga,nu
<A  HREF="http://www.kanga.nu/lists/listinfo/mud-dev">http://www.kanga.nu/lists/listinfo/mud-dev</A>

</PRE>

<!--X-Body-of-Message-End-->
<!--X-MsgBody-End-->
<!--X-Follow-Ups-->
<HR>
<ul compact><li><strong>Follow-Ups</strong>:
<ul>
<li><strong><A NAME="00713" HREF="msg00713.html">Re: [MUD-Dev] Embedding Python</A></strong>
<ul compact><li><em>From:</em> icecube#ihug,co.nz</li></ul>
</UL></LI></UL>
<!--X-Follow-Ups-End-->
<!--X-References-->
<!--X-References-End-->
<!--X-BotPNI-->
<UL>
<LI>Prev by Date:
<STRONG><A HREF="msg00295.html">Re: [MUD-Dev] Event Scheduling</A></STRONG>
</LI>
<LI>Next by Date:
<STRONG><A HREF="msg00297.html">[MUD-Dev] Raph's collection of MUD design Laws</A></STRONG>
</LI>
<LI>Prev by thread:
<STRONG><A HREF="msg00312.html">Re: [MUD-Dev] Raph's collection of MUD design Laws</A></STRONG>
</LI>
<LI>Next by thread:
<STRONG><A HREF="msg00713.html">Re: [MUD-Dev] Embedding Python</A></STRONG>
</LI>
<LI>Index(es):
<UL>
<LI><A HREF="index.html#00296"><STRONG>Date</STRONG></A></LI>
<LI><A HREF="thread.html#00296"><STRONG>Thread</STRONG></A></LI>
</UL>
</LI>
</UL>

<!--X-BotPNI-End-->
<!--X-User-Footer-->
<!--X-User-Footer-End-->
<ul><li>Thread context:
<BLOCKQUOTE><UL>
<LI><STRONG>Re: [MUD-Dev] Raph's collection of MUD design Laws</STRONG>, <EM>(continued)</EM>
<ul compact>
<LI><strong><A NAME="00301" HREF="msg00301.html">Re: [MUD-Dev] Raph's collection of MUD design Laws</A></strong>, 
Wes Connell <a href="mailto:wconnell#skotos,net">wconnell#skotos,net</a>, Sun 13 Feb 2000, 07:06 GMT
</LI>
<LI><strong><A NAME="00303" HREF="msg00303.html">Re: [MUD-Dev] Raph's collection of MUD design Laws</A></strong>, 
Caliban Tiresias Darklock <a href="mailto:caliban#darklock,com">caliban#darklock,com</a>, Sun 13 Feb 2000, 21:12 GMT
<UL>
<LI><strong><A NAME="00311" HREF="msg00311.html">Re: [MUD-Dev] Raph's collection of MUD design Laws</A></strong>, 
David Bennett <a href="mailto:ddt#discworld,imaginary.com">ddt#discworld,imaginary.com</a>, Mon 14 Feb 2000, 21:45 GMT
<UL>
<LI><strong><A NAME="00312" HREF="msg00312.html">Re: [MUD-Dev] Raph's collection of MUD design Laws</A></strong>, 
J C Lawrence <a href="mailto:claw#kanga,nu">claw#kanga,nu</a>, Mon 14 Feb 2000, 22:24 GMT
</LI>
</UL>
</LI>
</UL>
</LI>
</ul>
</LI>
<LI><strong><A NAME="00296" HREF="msg00296.html">[MUD-Dev] Embedding Python</A></strong>, 
icecube <a href="mailto:icecube#ihug,co.nz">icecube#ihug,co.nz</a>, Sun 13 Feb 2000, 00:10 GMT
<UL>
<LI><strong><A NAME="00713" HREF="msg00713.html">Re: [MUD-Dev] Embedding Python</A></strong>, 
icecube <a href="mailto:icecube#ihug,co.nz">icecube#ihug,co.nz</a>, Thu 23 Mar 2000, 20:58 GMT
<UL>
<LI><strong><A NAME="00715" HREF="msg00715.html">Re: [MUD-Dev] Embedding Python</A></strong>, 
J C Lawrence <a href="mailto:claw#kanga,nu">claw#kanga,nu</a>, Thu 23 Mar 2000, 21:13 GMT
</LI>
<LI><strong><A NAME="00716" HREF="msg00716.html">Re: [MUD-Dev] Embedding Python</A></strong>, 
Todd McKimmey <a href="mailto:rufus#wombatgames,com">rufus#wombatgames,com</a>, Thu 23 Mar 2000, 21:21 GMT
<UL>
<LI><strong><A NAME="00718" HREF="msg00718.html">Re: [MUD-Dev] Embedding Python</A></strong>, 
Oliver Jowett <a href="mailto:icecube#ihug,co.nz">icecube#ihug,co.nz</a>, Thu 23 Mar 2000, 22:46 GMT
</LI>
</UL>
</LI>
</UL>
</LI>
</UL>
</LI>
</UL></BLOCKQUOTE>

</ul>
<hr>
<center>
[&nbsp;<a href="../">Other Periods</a>
&nbsp;|&nbsp;<a href="../../">Other mailing lists</a>
&nbsp;|&nbsp;<a href="/search.php3">Search</a>
&nbsp;]
</center>
<hr>
</body>
</html>