Re: calling python procedures from tcl using tclpython

2005-07-07 Thread Michael Schlenker
chand wrote:
> Hi..
> 
> I am writing a Gui in TCL and my backend code is python. I want to call
> python procedure in tcl using tclpyhton. I want to know clearly how
> this should be implemented.
> 
> let's say I have procedure test_function(arg1,arg2 ...) defined in
> test.py.
> I want to call this procedure in tcl. Let me know how this should be
> achieved.
> The doubt basically have is how the tcl code knows in which .py file
> this procedure is defined.
> 
> currently I have wriiten this tcl code which is not working
> 
> package require tclpython
> set interpreter [python::interp new]
> $interpreter eval {def test_function(): arg1,arg2} ;
> python::interp delete $interpreter
> 
What does not work? You never load your file test.py anywhere inside,
you just evaluate 'def test_function(): arg1,arg2' so what are you
expecting to happen?

Your call to '$interpreter eval' lets you call arbitrary python code,
but you have to provide the python code that loads your function
definitions etc. I don't know python, but it should be a trivial code.

Michael


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


Re: automatic parallelization

2007-09-13 Thread Michael Schlenker
Mikhail Teterin schrieb:
> While C/C++ and Fortran have OpenMP (http://www.OpenMP.org/), there is
> nothing comparable in Tcl (nor, as far as I know, in the two other
> scripting languages).
> 
> Or is there? I'd like to, for example, have a version of foreach loop, that
> would split the tasks between concurrently executing threads in order to
> scale to the number of available CPUs:

For CPython you don't get any benefit from extra CPUs even if you tried
(unless the code inside your loop is specially written C code), due to
the GIL.

For Perl i don't know, their threading model was a bit heavy last time i
looked, but i might be off with that, so maybe its doable in Perl.

For Tcl you would at least get the benefit of multiple CPUs, but its
more message passing based thread model is probably not the best for
autoparallelization like OpenMP (but you could use the tsv:: api for
shared vars if you want to).

> 
> For example:
> 
>  pforeach image $images {
>   set exif($image) [extract_exif $image]
>  }
> 
> The script would be the same on a single- and a multi-CPU computer, but
> would automatically take advantage of multiple processors, when possible.

Its doable in principle, but as with OpenMP you need extra annotations
to make it workable.

If you have an event style script in Tcl you might be easier able to use
threads, as the thread::send -async api fits very well with the event
based style.

Michael

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