Re-enter python tcl interpreter problem

Pramod Kumar Singh pramod at tcsi.com
Wed Dec 8 15:10:39 EST 1999


Hi,

  I have the an interesting scenario.

  OM1 - Object Manager 1
  OM2 - Object Manager 2

  These object managers are multi-threaded and have the capability to
execute python implemented operations when a client executes an
operation on a object. Within these python operation I can also execute
a remote operation on another object residing on another object manager.
This remote operation invoke is done through tcl.

  e.g
  OBJ1 resides in OM1 and OBJ2 resides in OM2.
  OBJ1 has operation op1() and OBJ2 has operation op2()

  When a client invokes OBJ1.op1() on OM1, the python operation op1 is
executed, which in turn calls OBJ2.op2() on OM2. But op2() takes a lot
of time and thus holds the OM1 from receiving any other client request.
In order to resolve this problem, I made the tcl call release the main
thread (done in c++) and let the request continue in another thread.
This way OM1 is not blocked and can receive any number of request.

  Now here is the problem.
  When two clients are invoking operations simultaneously on OBJ1 in
OM1, my process OM1 crashes. Here is what happens.

  i)   The remote operation through tcl has released the main loop to
let OM1 receive any other request.
  ii)  OM1 is still executing the remote request through tcl in another
thread.
  iii) During this time another client has requested on OM1 OBJ1.op1()
and thus the tcl interpreter is re-entered to call the remote operation
of OBJ2.op2(). This is where the crash occurs.

  This gives me a conlusion that TCL interpreter cannot be re-entered
before a task is still going on in same tcl. interpreter. Is this
correct ? Is there any workaround for this ? Am I missing any kind of
flag or such ? Has anybody faced such a situation and resolved it.

  I did read about suggestions on using multi-threaded tcl 8.2.2, but
for my circumstance of software tied up to Python 1.5.1 I can't upgrade
to 8.2.2. Any other suggestions.

  Here is the error given by tcl interpeter in OM1.

TclExecuteByteCode: done instruction at pc 6: stack top 7 != entry stack
top 5
  Source: "OBJ2.op2 -sync"TclExecuteByteCode execution failure: end
stack top != start stack top

 I am using Python 1.5.1 and TCL/TK 8.0.5

The dbx stack trace is as follows

[7] TclExecuteByteCode(interp = 0x164128, codePtr = 0x101e58), line 710
in "tclExecute.c"
  [8] Tcl_EvalObj(interp = 0x164128, objPtr = 0x17c810), line 2640 in
"tclBasic.c"
  [9] Tcl_UplevelObjCmd(dummy = (nil), interp = 0x164128, objc = 1, objv
= 0x16778c), line 605 in "tclProc.c"
  [10] TclExecuteByteCode(interp = 0x164128, codePtr = 0x92490), line
956 in "tclExecute.c"
  [11] Tcl_EvalObj(interp = 0x164128, objPtr = 0x16d1c8), line 2640 in
"tclBasic.c"
  [12] TclObjInterpProc(clientData = 0x1b4b00, interp = 0x164128, objc =
3, objv = 0x167778), line 992 in "tclProc.c"
  [13] TclExecuteByteCode(interp = 0x164128, codePtr = 0x1e1da8), line
956 in "tclExecute.c"
  [14] Tcl_EvalObj(interp = 0x164128, objPtr = 0x16d5d0), line 2640 in
"tclBasic.c"
  [15] Tcl_Eval(interp = 0x164128, string = 0x133340 "Line.Find -sync"),
line 2448 in "tclBasic.c"
dbx: warning: can't find file ""
dbx: warning: see `help pathmap'
  [16] Tkapp_Call(0x153d28, 0x1d8500, 0x6d609b18, 0x0, 0x1d8640, 0x2),
at 0x6efa20e8
dbx: warning: can't find file ""
  [17] call_builtin(0x153ce0, 0x80da8, 0x0, 0x0, 0x109564, 0x153d28), at
0x6efde254
  [18] PyEval_CallObjectWithKeywords(0x153ce0, 0x80da8, 0x0, 0x0,
0x80da8, 0x1), at 0x6efddf84
  [19] eval_code2(0x1d8500, 0x0, 0x14c508, 0x1, 0x83, 0x1396aa), at
0x6efda754
  [20] call_function(0x0, 0x0, 0x0, 0x0, 0x133338, 0x6e696144), at
0x6efdeaf8
  [21] PyEval_CallObjectWithKeywords(0x14efd8, 0x1d5810, 0x0,
0x6d609fac, 0x6d609fa8, 0x1034d8), at 0x6efddf54

  Any help is highly appreciated.

 Thanks, Regards,

Pramod/



More information about the Python-list mailing list