This is the mail archive of the frysk@sources.redhat.com mailing list for the frysk project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

frysk and jython (Java Python)


Here's a little proof-of-concept showing jython (http://www.jython.org), the Python interpreter that works with Java, interacting with the frysk core.

I've included a running commentary (and I appologize in advance for my clear lack of Python foo :-), here goes:


The build system creates a little script gij.sh ($BUILD/frysk-core/gij.sh) that wraps frysk up so that it looks like a java byte code interpreter. Use that to load/run the jython interpreter:


cagney@localhost$ CLASSPATH=/usr/share/java/jython.jar ./gij.sh org.python.util.jython
Jython 2.2a0 on java1.4.2 (JIT: null)

Grap the process model's Manager, it knows were a few key things are; tell it to kick off the event-loop thread.


>>> from frysk.proc import Manager
>>> Manager.eventLoop.start ()

>>> h = Manager.host

Grap this machines Host. Since frysk is self-aware (it knows the location of itself within the host's process hierarchy), start examining the process model by looking at frysk.


>>> me = h.getSelf ()
>>> print me
{frysk.proc.LinuxProc@1226d58,id={ProcId,26184},state=unattached}

>>> print me.getCommand()
fryski

That's frysk built as a java interpreter.


>>> print me.getTasks()
[Linux{frysk.proc.LinuxTask@37a550,id={TaskId,26186},proc={frysk.proc.LinuxProc@1226d58,id={ProcId,26184},state=unattached},state=unattached}, Linux{frysk.proc.LinuxTask@37a5a0,id={TaskId,26185},proc={frysk.proc.LinuxProc@1226d58,id={ProcId,26184},state=unattached},state=unattached}, Linux{frysk.proc.LinuxTask@37a5f0,id={TaskId,26184},proc={frysk.proc.LinuxProc@1226d58,id={ProcId,26184},state=unattached},state=unattached}]

"task" is the linux kernel concept of a thread of execution; NPTL is implemented as a very thin layer over these tasks. This process has three tasks: main (running the interpreter); the frysk event loop; and the garbage collector.


>>> h.requestCreateAttachedProc (["sleep","1000"])

Tell the host to kick of a new process. Since frysk started it, it, as expected, appears below frysk in the process tree. Use sleep, so that the running process hangs around long enough for us to see it (by default everything is allowed to run):


>>> me.getChildren()
[{frysk.proc.LinuxProc@1226b28,id={ProcId,26187},state=startRunning}]
>>> child = me.getChildren()[0]
>>> print child.getTasks()
[Linux{frysk.proc.LinuxTask@37a3c0,id={TaskId,26187},proc={frysk.proc.LinuxProc@1226b28,id={ProcId,26187},state=startRunning},state=running}]
>>> child.getCommand()
'sleep'

Finally, lets look above frysk to see where this process sits within the process tree; iterate over the parents until the top-most process is reached:


>>> p = me
>>> while p:
... print p
Traceback (innermost last):
  (no code object) at line 0
  File "<console>", line 2
        print p
        ^
SyntaxError: invalid syntax
>>> while p:
...     print p
...     p = p.getParent ()
...
{frysk.proc.LinuxProc@1226d58,id={ProcId,26184},state=unattached}
{frysk.proc.LinuxProc@1226d90,id={ProcId,13825},state=unattached}
{frysk.proc.LinuxProc@1226dc8,id={ProcId,2781},state=unattached}
{frysk.proc.LinuxProc@1226e00,id={ProcId,1},state=unattached}
>>>

(did I mention my lack of Python foo? :-) Looking good.


What next? There are obviously a number of issues that will need to be addressed before this concept can be considered for mainline integration. Of those, several are worth mentioning:

- the graphical interface requires the addition of a per-interpreter / cli console window to wrap an interpreter thread
(yes, there is nothing technically stopping frysk from running multiple interpreters simultaneously).


- since frysk's core is both non-blocking and event-driven, requests such as requestCreateAttachedProc are processed asynchronously (ack comming back via an observer); an interpreter's life will be easier once the asynchronous interfaces are extended to include synchronized variants.

If you're interested in playing, the frysk interfaces are described in http://sourceware.org/frysk/javadoc/public/ ; they will obviously continue to rapidly evolve.

Andrew


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]