I tried something that was suggested last September 14th by Augusto Stoffel. I had not tried it because changing the sleep from 10 to 90 was my workaround.
One thing that might work is to block until the shell is ready with something like
(run-python)
(with-current-buffer *the-shell-buffer*
(while (not python-shell--first-prompt-received)
(accept-process-output (get-buffer-process (current-buffer)))))
modified lisp/org/ob-python.el
@@ -198,7 +198,10 @@ org-babel-python-initiate-session-by-key
(let ((python-shell-buffer-name
(org-babel-python-without-earmuffs py-buffer)))
(run-python cmd)
-
(sleep-for 0 10)))
+ (with-current-buffer py-buffer
+ (while (not python-shell--first-prompt-received)
+ (accept-process-output (get-buffer-process (current-buffer)))))
+ ))
((and (eq 'python-mode org-babel-python-mode)
(fboundp 'py-shell)) ; python-mode.el
(require 'python-mode)