Skip to content
Tcl Source Code History Of Ticket 3536564fffffffff
Login

History Of Ticket 3536564fffffffff

Artifacts Associated With Ticket 3536564fffffffff

  1. Ticket change [0069b23f06] (rid 119317) by anonymous on 2012-06-20 11:28:05:

    1. assignee initialized to: "andreas_kupries"
    2. cmimetype initialized to: "text/plain"
    3. comment initialized to:
      Hi, 
      
       I am looking to run a couple of processes in parallel. But a strange hang occurs randomly. I am invoking two tcl commands using open in parallel. Now after a while one of the process would just hang indefinitely which I am not able to understand why. The issue is easily reproducible on win 2008 server and other multi core machines. Am I doing something wrongly? What is the best way to do this? 
      
      To reproduce, you just have to create the files and run loop.bat. You should see the hang within 15-20 minutes. 
      
      Following are the files I am using 
      
      ******** 
      loop.bat 
      ****** 
      @echo off 
      :loop 
      tclsh 1.tcl 
      goto loop 
      
      ***************** 
      Contents of file 1.tcl 
      ***************** 
      #!/bin/sh 
      #DO NOT CHANGE THOSE 3 FIRST LINES \ 
      exec tclsh $0 "$@" 
      
      set status [catch { exec tclsh 2.tcl } outcmd] 
      puts $outcmd 
      exit 0 
      
      ******* 
      Contents of file 2.tcl 
      ***** 
      #!/bin/sh 
      #DO NOT CHANGE THOSE 3 FIRST LINES \ 
      exec tclsh $0 "$@" 
      
      set cmd1 "tclsh 6.tcl &" 
      set cmd2 "tclsh 5.tcl &" 
      set out1 "" 
      set out2 "" 
      
      proc isProcessDone { channel logText } { 
          gets $channel currentline 
          while {[eof $channel] == 0} { 
              set logText "$logText\n $currentline" 
              gets $channel currentline 
          } 
          return $logText 
      } 
      
      puts "hi" 
      set imChannel1 [open "| $cmd1"] 
      puts "hi1 $imChannel1" 
      set imChannel2 [open "| $cmd2"] 
      puts "hi2 $imChannel2" 
      #set imChannel3 [open "| $cmd"] 
      
      
      if { ${imChannel1} != "" } { 
              puts 1 
              fileevent $imChannel1 readable [set out1 [isProcessDone $imChannel1 $out1]] 
              puts 11 
              puts $out1 
      } 
      
      if { ${imChannel2} != "" } { 
              puts 2 
              fileevent $imChannel2 readable [set out2 [isProcessDone $imChannel2 $out2]] 
              puts 22 
              puts $out2 
      } 
      
      puts "bye" 
      
      exit 0 
      
      **** 
      Contents of 5.tcl and 6.tcl 
      ****** 
      #!/bin/sh 
      #DO NOT CHANGE THOSE 3 FIRST LINES \ 
      exec tclsh $0 "$@" 
      
      puts "\ncallexec 6 started" 
      puts "\ncallexec 6 terminated" 
      
      Please help. 
      
      TIA. 
      Deepanshu 
      
    4. foundin initialized to: "obsolete: 8.4.15"
    5. is_private initialized to: "0"
    6. priority initialized to: "5 Medium"
    7. resolution initialized to: "None"
    8. status initialized to: "Open"
    9. subsystem initialized to: "24. Channel Commands"
    10. title initialized to:
      tcl hangs on parallel execution of commands using open
      
    11. type initialized to: "Bug"
  2. Ticket change [27bd6f6ef0] (rid 88576) by anonymous on 2012-06-22 11:40:44:

    1. priority changed to: "7 High"
  3. Ticket change [09bc761349] (rid 113708) by andreas_kupries on 2012-07-18 00:33:04:

    1. closedate changed to: "2012-07-17T17:33:04"
    2. closer changed to: "andreas_kupries"
    3. icomment:
      Hello Deepanshu.
      
      Thank you for providing test scripts. Reviewing them I find fairly big problems in 2.tcl, and the attempted use of fileevents. First, the lines
      
          fileevent $imChannel1 readable [set out1 [isProcessDone $imChannel1 $out1]] 
      
      (and equivalent for channel 2) have the problem that 'isProcessDone' is executed immediately, and not in response to fileevents. Because you are using [...]-quoting which evaluates the command directly. This also means that while you are opening 2 pipes, you are then looking at them sequentially, not in parallel.
      
      Further, you are not reconfiguring your channel to be non-blocking, which is strongly recommended when working with fileevents. Otherwise your read/gets in a fileevent handler procedure can block. Making things look like a hang.
      
      Then 'isProcessDone' itself accesses the channel in a loop waiting for EOF. With fileevents such a loop would not be necessary, as your handler would get called when EOF is reached, allowing you to test and close, without an explicit loop.
      
      Lastly, as you are using tclsh no standard event loop is started (like wish would do), and you are not starting an event loop either (I see no 'vwait' command).
      
      With all these problems in the code I currently believe that the source of your problem (hang) is to be found in there, and not in the Tcl core itself.
      
      Examples of proper fileevent usage can be found at
          http://www.activestate.com/blog/2010/05/concurrency-tcl-events-without-getting-twisted
          http://wiki.tcl.tk/1757
          http://www.tcl.tk/man/tcl8.5/tutorial/Tcl40.html
      
      
    4. login: "andreas_kupries"
    5. mimetype: "text/plain"
    6. priority changed to: "4"
    7. resolution changed to: "Invalid"
    8. status changed to: "Pending"
    9. username: "andreas_kupries"
  4. Ticket change [ec04662b16] (rid 103638) by anonymous on 2012-07-19 00:01:33:

    1. icomment:
      Thanks for the update Andreas.
      
      I debugged the problem further and nailed it down to exec hanging on exit when invoked in a nested code.
      Say I have 1.tcl which contains exec 2.tcl
      now 2.tcl says exec tclsh 3.tcl 
      and 3.tcl says puts "Hello"
      
      I have noticed this problem on 64-bit Windows multi-core machines with 32-bit Tcl 8.4 and also 8.6.
      
      Please let me know if you need more info.
      
      
    2. login: ""
    3. mimetype: "text/plain"
    4. status changed to: "Open"
    5. username: ""
  5. Ticket change [0f65ad5158] (rid 94782) by anonymous on 2012-08-02 01:02:25:

    1. foundin changed to: "None"
    2. icomment:
      Hi Andreas,
      
        Can you please see if this nesting exec problem on 64-bit machines can be looked into? I have seen this problem with ActiveTcl 8.6 also.
      
      Regards,
      Deepanshu
      
      
    3. login: ""
    4. mimetype: "text/plain"
    5. resolution changed to: "Rejected"
    6. username: ""
  6. Ticket change [1750a9c3f0] (rid 122468) by dkf on 2012-08-02 04:51:13:

    1. icomment:
      If the problems are due to Tcl scripts that simply cannot work, that's not a bug in Tcl's implementation but rather in the scripts. This is not a general Tcl script writing support forum (that would be the comp.lang.tcl newsgroup, or possibly the Stack Overflow website).
      
      
    2. login: "dkf"
    3. mimetype: "text/plain"
    4. resolution changed to: "Invalid"
    5. username: "dkf"
  7. Ticket change [fb3805b1db] (rid 92014) by ferrieux on 2012-08-02 18:25:30:

    1. closedate changed to: "2012-08-02T11:25:30"
    2. closer changed to: "ferrieux"
    3. icomment:
      
      
      allow_comments - 1
      
      Non-dev comments closed now. Hint: go to comp.lang.tcl for further assistance.
      
      
    4. login: "ferrieux"
    5. mimetype: "text/plain"
    6. status changed to: "Closed"
    7. username: "ferrieux"