wierd threading behavior

2005-10-14 Thread Qun Cao
Hello,

I am just starting to play threading in python, here is a really
interesting problem I am very curious about:
"
import thread
def main():
thread.start_new(test.())

def test():
print 'hello'

main()
"
this program doesn't print out 'hello' as it is supposed to do.
while if I change main() into :
"
def main():
while 1:
thread.start_new(test.())
"
It goes on to print 'hello' forever.

while if I use:
"
def main():
for i in range(5):
print i
thread.start_new(test.())
"
It prints out 1,2,3,4,5 in main(), but still doesn't print out anything
from test()!

This is really wierd behavior for me, I am sure it's just something
simple&stupid, please enlighten me! 

Thanks, 
qun

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: threading/forking and IPC

2005-10-14 Thread Qun Cao
Thanks David, 
This seems like the exact thing I am looking for!

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wierd threading behavior

2005-10-14 Thread Qun Cao
Thanks Sam,
That was a stupid typo ( yeah, I actually typed it in :), it should be
(test,()).
I am using python 2.4.1 in ubuntu.  I do aware that threading.Thread is
prefered,
but I did not realize thread is deprecated.  It is still a mysterious
behavior anyhow. :)

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wierd threading behavior

2005-10-17 Thread Qun Cao
Thanks Neil, that's very useful to know.

Qun

-- 
http://mail.python.org/mailman/listinfo/python-list


beginner questions on embedding/extending python with C++

2006-08-08 Thread Qun Cao
Hi Everyone,

I am a beginner on cross language development. My problem at hand is to
build a python interface for a C++ application built on top of a 3D
game engine.  The purpose of this python interface is providing a
convenient scripting toolkit for the application.  One example is that
a user can write a python script like:
   player = Player()
   game.loadPlayer(player)
   player.moveTo(location)
To configure the game environment.

I am trying to figure out how to make this happen.  I only have the
vague idea that this concerns embedding/extending python with C++, but
after reading Python Doc, SWIG, BOOST.Python, I am still not sure how
to architecture it.

Since the main program is still going to be the C++ application, I
guess we need to embedding the python scripts in the C++ code.  So at
initialization stage, the python script needs to be loaded into the C++
code.  And this code can be simple, like
player = Player()
game.loadPlayer(player)


But for this to work, the python code needs to know the Player class,
is it right? Does that mean I need to build a python wrapper class for
Player and "import Player" in the python code?  But because this
application is built on top of a game engine, Player class inherits
many classes from there, I cannot possibly wrapping them all, right?
Also, some global objects are probably needed in this code of adding
players, how can the python code access them?

I know I probably don't have a grasp of basics here,  please kindly
enlighten me!

Btw, if you can point me to any source code of non-trivial projects
utilizing SWIG/Boost.Python, that would be very helpful.  I found the
examples on the tutorials are far too simple.

Thank you very much, 
Qun

-- 
http://mail.python.org/mailman/listinfo/python-list


(Boost.Python) How to load header files?

2006-08-08 Thread Qun Cao
Hi Everyone,

I just started to use boost.python and having problem trying to get my
first program working.

I have a C++ class foo.cpp, defined in foo.h, I wrote a wrapper class
for it to generate a python module.

#include "Foo.h"

#include 
#include 
#include 
using namespace boost::python;

BOOST_PYTHON_MODULE(mymodule)
{
   class_("Foo")
.def ("init", &Foo:init)

}

The problem is that when I bjam it, the compiler cannot find the header
file , although I had the location of Foo.h added into $PATH.  I
can make it work by copying Foo.h into the working directory, but Foo.h
is also depended on other libraries, so I need a generic way to
recognize the header files.

Thanks for any hit,
Qun

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: beginner questions on embedding/extending python with C++

2006-08-08 Thread Qun Cao
Thanks Diez,
It is a good relief that I only need to wrap the classes I need.  I
decide to try Boost first because it seems to have a wider audience
than SIP, but I would definately look into SIP if I want to do Qt
development in the future.


Diez B. Roggisch wrote:
> > Since the main program is still going to be the C++ application, I
> > guess we need to embedding the python scripts in the C++ code.  So at
> > initialization stage, the python script needs to be loaded into the C++
> > code.  And this code can be simple, like
> > player = Player()
> > game.loadPlayer(player)
> >
> >
> > But for this to work, the python code needs to know the Player class,
> > is it right? Does that mean I need to build a python wrapper class for
> > Player and "import Player" in the python code?  But because this
> > application is built on top of a game engine, Player class inherits
> > many classes from there, I cannot possibly wrapping them all, right?
> > Also, some global objects are probably needed in this code of adding
> > players, how can the python code access the
> You should look into SIP besides the tools you already mentioned - IMHO it
> is the best choice for wrapping C++.
>
> And yes, you need to wrap classes - but only those that are of interest for
> you! So if you need Player, wrap Player. No need to wrap it's base-classes,
> unless you want these for other purposes, too.
>
> And for global objects I'd create functions which return these.
>
> I suggest you try and download a project that uses one of the possible
> toolkits for wrapping - the most prominent user of SIP is of course PyQt.
> Go and have a look at the source, how things are done. There aresome
> tutorials I think, google should help you on that.
> 
> HTH Diez

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: beginner questions on embedding/extending python with C++

2006-08-08 Thread Qun Cao
Thanks for all the good pointers!
I am still reading throught them, but Boost seems to be the way to go!

Roman Yakovenko wrote:
> On 8 Aug 2006 02:28:31 -0700, Qun Cao <[EMAIL PROTECTED]> wrote:
> > Hi Everyone,
> >
> > I am a beginner on cross language development. My problem at hand is to
> > build a python interface for a C++ application built on top of a 3D
> > game engine.  The purpose of this python interface is providing a
> > convenient scripting toolkit for the application.
>
> As for me, Boost.Python is the way to go.
>
> Fortunately you are not the first one, and I hope not the last one :-) :
>
> http://language-binding.net/pyplusplus/quotes.html#who-is-using-pyplusplus
> 1. Python-OGRE
>   * http://lakin.weckers.net/index_ogre_python.html
>   * http://tinyurl.com/mvj8d
>
> 2. http://cgkit.sourceforge.net/ - contains Python bindings for Maya C++ SDK
>
> 3. PyOpenSG - https://realityforge.vrsource.org/view/PyOpenSG/WebHome
>The goal of PyOpenSG is to provide python bindings for the OpenSG
>scene graph.
>
> > Since the main program is still going to be the C++ application, I
> > guess we need to embedding the python scripts in the C++ code.
>
> Boost.Python is the only tool that provides complete functionality(
> extending and
>   embedding ). Also I think cgkit is dealing with the problem too.
>
> > But for this to work, the python code needs to know the Player class,
> > is it right?
>
> Right.
>
> Does that mean I need to build a python wrapper class for
> > Player and "import Player" in the python code?  But because this
> > application is built on top of a game engine, Player class inherits
> > many classes from there, I cannot possibly wrapping them all, right?
>
> It depends on how much functionality you want to export.
>
> > Also, some global objects are probably needed in this code of adding
> > players, how can the python code access them?
>
> Boost.Python provides the functionality you need.
>
> > Btw, if you can point me to any source code of non-trivial projects
> > utilizing SWIG/Boost.Python, that would be very helpful.  I found the
> > examples on the tutorials are far too simple.
>
> Those are tutorials, they should be simple, right :-) ?
>
> --
> Roman Yakovenko
> C++ Python language binding
> http://www.language-binding.net/

-- 
http://mail.python.org/mailman/listinfo/python-list