intermittent usage of shell.py and of pyclips

Pyc Liph
2008-12-21
2013-04-25
  • Pyc Liph
    Pyc Liph
    2008-12-21

    This is to provide additional instruction to less initiated.

    In his excellent "A simple CLIPS shell using PyCLIPS" Francesco writes 'you can use both CLIPS and PyCLIPS at the same time'. It took me a while to figure out an intermittent use, of either the shell (the shell.py that is) or of the pyclips. It can be done like this:

    Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52)
    [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import shell
    >>> clipsh = shell.Shell()
    >>> clipsh.Run()
    CLIPS[1/1]> (assert (duck))
    <Fact-0>
    CLIPS[2/1]> (facts)
    f-0     (duck)
    For a total of 1 fact.
    CLIPS[3/1]> >>>
    >>> import shell
    >>> shell.Shell().Run()
    CLIPS[1/1]> (assert (hello))
    <Fact-1>
    CLIPS[2/1]> (assert (hello))
    FALSE
    CLIPS[3/1]> (assert (hello))
    FALSE
    CLIPS[4/1]> >>> import clips
    >>> clips.PrintFacts()
    f-0     (duck)
    f-1     (hello)
    For a total of 2 facts.
    >>> clips.Assert("(eagle)")
    <Fact 'f-2': fact object at 0xb79648e0>
    >>> clips.PrintFacts()
    f-0     (duck)
    f-1     (hello)
    f-2     (eagle)
    For a total of 3 facts.
    >>> shell.Shell().Run()
    CLIPS[1/1]> (facts)
    f-0     (duck)
    f-1     (hello)
    f-2     (eagle)
    For a total of 3 facts.
    CLIPS[2/1]>

    Such an intermittent use is still very convenient.

    I am not sure if a true concurrency of the shell and pyclips usage can be achieved such as, for example, from two terminal windows accessing the same python. Francesco?

    One other minor simplification, perhaps, in terms of using the shell.py. If one executes python in directory where the shell.py exists then there is no need to have the PYTHONPATH environment variable set up.
    Pyc.

     
    • Hi Pyc,

      well, accessing the same Python from two different windows would not be simple... maybe it's the job for a Python server application running PyCLIPS. However, one can't achieve *true* multithreading using PyCLIPS (as I state here: http://pyclips.sourceforge.net/web/?q=node/10\) because the underlying CLIPS engine is too stateful. Python too does not allow true multithreading, as every low-level operation locks the Global Interpreter Lock, so multiple attempts to access CLIPS data from concurrent processes that query a single, pseudo-multithreaded Python server, should be still safe.

      When Python will remove the GIL, then I'll be in serious trouble! ;-)

      F.