There is a weblogic python script that takes a thread dump and sleeps for 10 or 20 seconds then takes another one after time.sleep(30), thread dumps are working fine, but the sleep method time.sleep(20) is not working.
Tried both import time
and from time import sleep
as well.
Getting this error below
AttributeError: java package 'weblogic.time' has no attribute 'sleep'
The reason you'd want to use wait() here is because wait() is non-blocking, whereas time.sleep() is blocking. What this means is that when you use time.sleep() , you'll block the main thread from continuing to run while it waits for the sleep() call to end. wait() solves this problem.
The Timer is another method available with Threading, and it helps to get the same functionality as Python time sleep. The working of the Timer is shown in the example below: Example: A Timer takes in input as the delay time in Python in seconds, along with a task that needs to be started.
Python time sleep function is used to add delay in the execution of a program. We can use python sleep function to halt the execution of the program for given time in seconds. Notice that python time sleep function actually stops the execution of current thread only, not the whole program.
This one worked for me : https://community.oracle.com/thread/3560679
import time as systime
systime.sleep(10)
The problem here is that the weblogic.time
package is shadowing the stdlib time
module. So, when you try to import time
, you're getting the former, not the latter.
(And weblogic.time
has nothing in it but a subpackage or module weblogic.time.common
, so you get an error trying to use its sleep
function. But that's probably a good thing—better than it had a function named sleep
that didn't do what you expected.)
If you were developing weblogic
itself, I could explain how to not do that… but if you're just using weblogic
, that's not going to help you.
If you're doing something like from weblogic import *
earlier, the solution is simple: Just don't do that. Otherwise… it will be more complicated to work around.
But if all you need to do is block your interpreter thread for 20 seconds, you can do that with the Java Thread.sleep(20000)
. See this tutorial, but really, you don't need to know much more than that the Java method takes integer milliseconds instead of float seconds. And then you don't need time
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With