Here is sample python code that runs with python3, but am sure would run
with python2 as well.
The python code has two functions: chat_1 and chat_2. Each function even
imports opencog bindings independently. But it seems when both
functions are executed one after the other, an error occurs (the error
message found just after the python code).
My guess is the functions use two different variables "atomspace" and this
seems to cause the error. But I can't figure out what the error means or
what the real cause is.
The only way to solve this problem seems to use multiprocessing
functionality. When multiprocessing is used by calling the proc( ) function
in the code below, then
no errors come up. But when threading or simply calling the functions one
after the other, the error appears (i.e. calling the functions thrd( ) and
vanilla ( ) ).
Even calling the function chat_1 twice causes an error as done in the thrd
( ) function that uses separate threads to run the function chat_1 .
Here is sample python code and below it the error that appears when either
vanilla( ) or thrd( ) is called but not when proc( ) is called
# Tested on python3.4/3.5
> import time
> import multiprocessing
> import threading
>
> def chat_1():
>
> from opencog.atomspace import AtomSpace
> from opencog.scheme_wrapper import scheme_eval_h
>
> atomspace = AtomSpace()
>
> scheme_eval_h(atomspace, "(use-modules (opencog))")
> scheme_eval_h(atomspace, "(use-modules (opencog nlp relex2logic))")
> scheme_eval_h(atomspace, "(use-modules (opencog openpsi))")
> scheme_eval_h(atomspace, "(use-modules (opencog eva-behavior))")
> scheme_eval_h(atomspace, "(use-modules (opencog ghost))")
>
> print('len(atomspace) =',len(atomspace))
>
> scheme_query_1 = '(ghost-parse "s: (hi robot) Hello human")'
> scheme_query_2 = '(test-ghost "hi robot good morning")'
>
> scheme_eval_h(atomspace, scheme_query_1)
>
> print('len(atomspace) =', len(atomspace))
>
> scheme_eval_h(atomspace, scheme_query_2)
>
> def chat_2():
>
> from opencog.atomspace import AtomSpace
> from opencog.scheme_wrapper import scheme_eval_h
>
> atomspace = AtomSpace()
>
> scheme_eval_h(atomspace, "(use-modules (opencog))")
> scheme_eval_h(atomspace, "(use-modules (opencog nlp relex2logic))")
> scheme_eval_h(atomspace, "(use-modules (opencog openpsi))")
> scheme_eval_h(atomspace, "(use-modules (opencog eva-behavior))")
> scheme_eval_h(atomspace, "(use-modules (opencog ghost))")
>
> print('len(atomspace) =',len(atomspace))
>
> scheme_query_1 = '(ghost-parse "s: (hi robot) Hello human")'
> scheme_query_2 = '(test-ghost "hi robot good morning")'
>
> scheme_eval_h(atomspace, scheme_query_1)
>
> print('len(atomspace) =', len(atomspace))
>
> scheme_eval_h(atomspace, scheme_query_2)
>
> def vanilla():
> chat_1()
> time.sleep(5)
> chat_2()
>
> def proc():
> p1 = multiprocessing.Process(target=chat_1)
> p1.start()
> # p1.join()
> # time.sleep(5)
> p2 = multiprocessing.Process(target=chat_2)
> p2.start()
> # p2.join()
>
> def thrd():
> t1 = threading.Thread(target=chat_1)
> t1.start()
> time.sleep(5)
> t2 = threading.Thread(target=chat_1)
> t2.start()
>
> if __name__ == '__main__':
>
>
> # proc()
> # thrd()
> # vanilla()
>
> pass
>
>
Error that appears when either calling vanilla( ) or thrd( ) but not proc( )
> len(atomspace) = 3624
> [2018-03-21 10:12:04:920] [WARN] [GHOST] Did you forget to link a goal to
> the rule?
> len(atomspace) = 3825
> [2018-03-21 10:12:04:990] [INFO] [GHOST] Say: "Hello human"
> len(atomspace) = 0
> Traceback (most recent call last):
> File "/***/pra5.py", line 96, in <module>
> vanilla()
> File "/***/pra5.py", line 63, in vanilla
> chat_2()
> File "/***/pra5.py", line 53, in chat_2
> scheme_eval_h(atomspace, scheme_query_1)
> File "scheme_wrapper.pyx", line 49, in
> opencog.scheme_wrapper.scheme_eval_h
> (/***/atomspace/build/opencog/cython/opencog/scheme_wrapper.cpp:1198)
> RuntimeError: Backtrace:
> In ice-9/boot-9.scm:
> 157: 14 [catch #t #<catch-closure 1cc55a0> ...]
> In unknown file:
> ?: 13 [apply-smob/1 #<catch-closure 1cc55a0>]
> In ice-9/boot-9.scm:
> 157: 12 [catch #t #<catch-closure 1cc5480> ...]
> In unknown file:
> ?: 11 [apply-smob/1 #<catch-closure 1cc5480>]
> ?: 10 [call-with-input-string "(ghost-parse \"s: (hi robot) Hello
> human\")" ...]
> In ice-9/boot-9.scm:
> 2320: 9 [save-module-excursion #<procedure 1848d20 at
> ice-9/eval-string.scm:65:9 ()>]
> In ice-9/eval-string.scm:
> 44: 8 [read-and-eval #<input: string 1b9d4e0> #:lang ...]
> 37: 7 [lp (ghost-parse "s: (hi robot) Hello human")]
> In system/base/lalr.upstream.scm:
> 1927: 6 [___run]
> In opencog/ghost/cs-parse.scm:
> 320: 5 [#<procedure 28adde0 (___stack ___sp ___goto-table ___push
> yypushback)> # ...]
> In opencog/ghost/translator.scm:
> 409: 4 [create-rule ((lemma . "hi") (lemma . "robot")) ((action # #)) ()
> ...]
> 215: 3 [process-pattern-terms (# # # #)]
> In unknown file:
> ?: 2 [cog-new-link 58 #<Invalid handle> (VariableNode "$S")
> ]
> In ice-9/boot-9.scm:
> 102: 1 [#<procedure 159b200 at ice-9/boot-9.scm:97:6 (thrown-k . args)>
> C++-EXCEPTION ...]
> In unknown file:
> ?: 0 [apply-smob/1 #<catch-closure 1cc5440> C++-EXCEPTION ...]
>
> ERROR: In procedure apply-smob/1:
> ERROR: In procedure cog-new-link: Expecting name and state, got size 1
> (/***/atomspace/opencog/atoms/core/StateLink.cc:32)
> Function args:
> (#<Invalid handle> (VariableNode "$S")
> )
> ABORT: C++-EXCEPTION
> (/***/atomspace/opencog/guile/SchemeEval.cc:930)
>
> Process finished with exit code 1
>
--
You received this message because you are subscribed to the Google Groups
"opencog" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/opencog.
To view this discussion on the web visit
https://groups.google.com/d/msgid/opencog/201dff6a-fc4b-4c7b-bad7-57851194e262%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.