jupyter_client icon indicating copy to clipboard operation
jupyter_client copied to clipboard

hang when calling get_shell_msg() before execute(..)

Open bschnurr opened this issue 6 years ago • 1 comments

ipython 7.4.0 ipykernel 5.1.0 pyzmq (18.0.0) or (18.0.1)

Previous versions of ipython didn't have this issue but it related to the newer pyzmq lib.

Fixes: downgrading pyzmq to 17.1.3 seems to fix the issue. for now changing get_shell_msg(block=true) to get_shell_msg(timeout=0.1) is a workaround

similar to issue #429

code below will delay calling execute so that get_shell_msg(..) can be called first.

import jupyter_client
import threading
import time

code = "import time\n" + "print(1)\n" + "time.sleep(10)\n" + "print(2)"
autoCode = "time."

def MyThread ():
  
    commands = \
    [
        '1+1',
        'a=5',
        'b=0',
        'b',
        'print()',
        'print("hello there")',
        '10',
        'a*b',
        'a',
        'a+b',
    ]
    #delay calling execute
    time.sleep(2)   
    print("will start execute")
  
    for command in commands:
        print(">>>" + command)
        out = kc.execute(command)

        if out: print(out)
        time.sleep(1)       
        
        

def MyThread2 ():
    while True:
        print("iopub will wait")
        reply =kc.get_iopub_msg(block=True)
        print("iopub complete", reply)
        time.sleep(2)


def MyThread3 ():
    while True:
        print("shell will wait")
        reply =kc.get_shell_msg(block=True)
        print("shell complete", reply)
        time.sleep(2)


km, kc = jupyter_client.manager.start_new_kernel(kernel_name='python')

t1 = threading.Thread(name="1", target=MyThread)
t1.start()
t2 = threading.Thread(name="2", target=MyThread2)
t2.start()
t3 = threading.Thread(name="3", target=MyThread3)
t3.start()

t1.join()
t2.join()
t3.join()

print("everything is done")

bschnurr avatar Apr 25 '19 22:04 bschnurr

bump I just ran into this myself. Is anyone able to take a look at this? Thanks!

AdamYoblick avatar Aug 15 '22 22:08 AdamYoblick