I tested the following code, and hereby I confirm that switching to java.lang.Thread
solves the problem experienced with Python’s time
module.
import system.date
from java.lang import Exception as JException, Thread
def java_sleep():
print 'Thread.sleep'
print system.date.now()
Thread.sleep(5000)
print system.date.now()
def py_sleep():
print 'time.sleep'
import time
print system.date.now()
time.sleep(5)
print system.date.now()
try:
java_sleep()
py_sleep()
except JException, e:
print e.message
Output:
>>>>
Thread.sleep
Tue Apr 14 22:01:02 CEST 2020
Tue Apr 14 22:01:07 CEST 2020
time.sleep
Cannot create PyString with non-byte value
>>>>
But still mind-boggling that after multiple attempts calling Python’s time.sleep
does work without throwing an error; and after one successful execution the error occurs no more.
I’ll be making the switch to Thread.sleep
.
Thanks, @KathyApplebaum and @pturmel.