sleep

Inaccurate time.sleep() with Python 3.x and Windows 7

二次信任 提交于 2019-12-08 08:48:51
问题 Following on from this post, I've identified a non-functional implementation of Python's time.sleep() function under Windows 7 (Enterprise, 64-bit and Python 3.4.4). Here's the reference .py script: import threading, time def Return(): return def Setup(): for _ in range(10): time_before = time.time() Return() wait_delay = -time.time() delays = [] InputFrequency = 60 while (time.time() - time_before) < (1 / InputFrequency): time.sleep(0) wait_delay += time.time() delays.append(wait_delay)

Microsecond Sleep in Linux kernel

独自空忆成欢 提交于 2019-12-08 06:33:38
问题 udelay() , mdelay() , usleep_range() all are giving run time errors: symbol lookup error: undefined symbol: __const_udelay I'm trying with ns3-DCE-linux, hence I'm able to see the error but in Linux Kernel, I get a kernel panic. From here udelay() is defined as a macro. #define udelay(n) \ ({ \ if (__builtin_constant_p(n)) { \ if ((n) / 20000 >= 1) \ __bad_udelay(); \ else \ __const_udelay((n) * 0x10c7ul); \ } else { \ __udelay(n); \ } \ }) From here mdelay() is defined as a macro which uses

Run python script after another is terminated

末鹿安然 提交于 2019-12-08 05:11:15
问题 I have a python script that takes several hours to complete. I usually run it as: python myscript.py arg1 arg2 ... argN 2> log.err > log.out & I'd like to have a shell script that runs several time the same python script (with different parameters). This script has to start the second python script ONLY when the first one has terminated and so on. I think I should use PID of the processes and iteratively check using sleep within some while loops. Any suggestions? The scripts are executed in a

system-function call asynchron?

╄→гoц情女王★ 提交于 2019-12-08 04:49:54
问题 At one place in a code i call an external tool with the system-Call. I work with Wine and program with C. The call is like this: system("blabla.exe outfile"); The command is dynamically generated to change the outfile. A few lines later i try to open the generated file with fopen , but fopen returns NULL . If i change the call to the following everything works: system("blabla.exe outfile"); Sleep(2000); But i don't like to wait 2 seconds... And this solution is very bad. I think the system

Does sleep() interfere with scanf()?

删除回忆录丶 提交于 2019-12-08 04:00:18
问题 I have two threads xThread : Continuously Prints X on the console inputThread : Gets input from the stdin The continuous printing stops when the user enters 'C' or 'c' #include<stdio.h> #include<sys/select.h> #include<pthread.h> #define S sleep(0) int read_c = 0; pthread_mutex_t read_c_mutex = PTHREAD_MUTEX_INITIALIZER; void* inputThread_fn(void* arg) { char inputChar; while(1) { S; printf("\nChecking input"); scanf("%c",&inputChar); if(inputChar=='C' || inputChar == 'c') { pthread_mutex

Throttle CPU usage of only one thread intentionally

孤街醉人 提交于 2019-12-08 03:55:02
问题 There are a couple of other similar questions on SO, but none of them have satisfactory/relevant answers. I have a single threaded C++ program which does something essentially like this: while(true) { //do things which are cpu bound } The problem is that when I run this program it is usually the only process on my whole computer that is doing active work. With nothing else to schedule, the OS naturally schedules this program heavily and my CPU usage shoots through the roof, which I do not

Improvements to this bash script to simulate “tail --follow”

巧了我就是萌 提交于 2019-12-07 18:45:00
问题 I need to remote tail log files such that the tailing continues working even when the file is rolled over. My attempts to do so, started by directly using the tail command over ssh: ssh root@some-remote-host tail -1000f /some-directory/application.log | tee /c/local-directory/applicaiton.log That allows me to filter through /c/local-directory/applicaiton.log locally using Otroslogviewer (which was the original purpose of trying to tail the log file locally). The above stops tailing when the

Java 复习 —— 线程相关方法介绍

大城市里の小女人 提交于 2019-12-07 15:23:52
1、sleep() 使当前线程(即调用该方法的线程)暂停执行一段时间,让其他线程有机会继续执行,但它并不释放对象锁(如果是在Synchronized块中的话, 他是不会释放锁的 )。也就是说如果有synchronized同步块,其他线程仍然不能访问共享数据。注意该方法是个静态方法,但是系统会自动识别具体哪个线程调用了休眠时间。 例如有两个线程同时执行(没有synchronized)一个线程优先级为MAX_PRIORITY,另一个为MIN_PRIORITY,如果没有Sleep()方法,只有高优先级的线程执行完毕后,低优先级的线程才能够执行;但是高优先级的线程sleep(500)后,低优先级就有机会执行了。 总之,sleep()可以使低优先级的线程得到执行的机会,当然也可以让同优先级、高优先级的线程有执行的机会。 注意:我们都知道,如果所有子线程都还没有执行完毕,那么主线程(main)是不会退出的;当然如果这些子线程都是守护线程的话,也就是在线程start之前设置为setDaemon(true);这个时候如果主线程运行完了,那么子线程也就会跟着消亡。 在做单元测试的时候,我发现就算我的所有子线程都是非守护线程,但是在子线程进入之后我就让他睡眠1秒钟,结果发现,主线程运行完之后,子线程也都退出了,除非我在主线程中睡得更久,程序才会继续执行。 2、join() join()方法

OS X Cocoa timer not fired when application on background

…衆ロ難τιáo~ 提交于 2019-12-07 14:32:56
问题 A third-party library provides a function I need to call every 100ms. Setting up a timer to do that works very well as long as my app is on foreground. When my app is on background timer works for a while but after a about a minute timer is called only after 10 second delay. The same happened when I created a separate thread with usleep-function. Is there any way I can keep timer running while my app is on background? 回答1: Use beginActivityWithOptions:reason: to disable app nap for your

Robot.delay(int) versus Thread.sleep(long)

僤鯓⒐⒋嵵緔 提交于 2019-12-07 11:36:30
问题 I have a program whose only purpose is to drive a java.awt.Robot in an infinite loop until an exit condition is met. The robot performs a number of actions in quick succession, which require a standard UI delay between them. For this, I use java.awt.Robot.setAutoDelay(int ms) , which appears to be designed for precisely this purpose. At other times, however, I need to insert arbitrarily long delays for operations to complete. I appear to have a choice between using java.awt.Robot.delay(int ms