time-limiting

Python timeout context manager with threads

江枫思渺然 提交于 2020-01-12 07:15:34
问题 I have timeout context manager that works perfectly with signals but it raises error in multithread mode because signals work only in main thread. def timeout_handler(signum, frame): raise TimeoutException() @contextmanager def timeout(seconds): old_handler = signal.signal(signal.SIGALRM, timeout_handler) signal.alarm(seconds) try: yield finally: signal.alarm(0) signal.signal(signal.SIGALRM, old_handler) I've seen decorator implementation of timeout but I don't know how to pass yield inside

How to limit the execution time of a function in c sharp?

人盡茶涼 提交于 2019-12-30 02:57:07
问题 I've got a problem. I'm writing a benchmark and I have a function than is either done in 2 seconds or after ~5 minutes(depending on the input data). And I would like to stop that function if it's executed for more than 3 seconds... How can I do it? Thanks a lot! 回答1: The best way would be that your function can check its execution time often enough to decide to stop it it takes too long. If this is not the case, then run the function in a separate thread. In your main thread start a 3 seconds

How to set a pop up time limit in python? [duplicate]

非 Y 不嫁゛ 提交于 2019-12-25 12:41:05
问题 This question already has answers here : How to set time limit on raw_input [duplicate] (6 answers) Closed 5 years ago . I want to have a time limit in order to enter the input in the following code. In other words, there should be a timer tracking the time and if it exceeds the limit, the code should print out a message like "Game over" automatically without hitting any key. it is a sort of pop-up. def human(player, panel): print print_panel(panel) print 'Your Turn! , Hint: "23" means go to

iPhone: 5 seconds video capture

我们两清 提交于 2019-12-24 01:44:56
问题 I would like to write code so that when the user presses a button, the camera is launched and records 5 seconds of video. In other words I want to have video capture but with a time limit. Is there something inside the UIImagePickerController or other parts of the framework that would allow doing this? Thank you. 回答1: There is nothing that allows you to directly do this. But you can very easily use UIImagePickerController's startVideoCapture to begin the capture and then call stopVideoCapture

python setting limit for running time with while loop

六月ゝ 毕业季﹏ 提交于 2019-12-14 00:40:59
问题 I have some questions related to setting the maximum running time in python. In fact, I would like to use pdfminer to convert the pdf files to .txt. The problem is that very often, some files are not possible to decode and take extremely long time. So I want to set time.time() to limit the conversion time for each file to 20 seconds. In addition, I run under windows so I cannot use signal function. I succeeded in running the conversion code with pdfminer.convert_pdf_to_txt() (in my code it is

Travis-CI - How is time limit counted for builds? (Sum of all jobs or time of longest one)?

萝らか妹 提交于 2019-12-09 04:52:02
问题 Let's say i have repo which for each push (build) starts 4 jobs (diffrent environment/compilers etc.). There is time limit for builds - 50min. Is it counted as sum of times of all builds (like in left panel), or is it independant for each job? Example: 4 builds, each taking 20minute - will it timeout becouse it will be counter as 80min or will it be ok and count as 20min (time of longest job)? 回答1: The Travis CI documentation is pretty clear about this. A build consists of one or many jobs.

Python timeout context manager with threads

落花浮王杯 提交于 2019-12-03 12:38:40
I have timeout context manager that works perfectly with signals but it raises error in multithread mode because signals work only in main thread. def timeout_handler(signum, frame): raise TimeoutException() @contextmanager def timeout(seconds): old_handler = signal.signal(signal.SIGALRM, timeout_handler) signal.alarm(seconds) try: yield finally: signal.alarm(0) signal.signal(signal.SIGALRM, old_handler) I've seen decorator implementation of timeout but I don't know how to pass yield inside class derived from threading.Thread . My variant won't work. @contextmanager def timelimit(seconds):

Travis-CI - How is time limit counted for builds? (Sum of all jobs or time of longest one)?

╄→尐↘猪︶ㄣ 提交于 2019-12-03 07:11:56
Let's say i have repo which for each push (build) starts 4 jobs (diffrent environment/compilers etc.). There is time limit for builds - 50min. Is it counted as sum of times of all builds (like in left panel), or is it independant for each job? Example: 4 builds, each taking 20minute - will it timeout becouse it will be counter as 80min or will it be ok and count as 20min (time of longest job)? The Travis CI documentation is pretty clear about this. A build consists of one or many jobs. The limit is enforced for each job: There is no timeout for a build; a build will run as long as all the jobs

How to limit the execution time of a function in c sharp?

别等时光非礼了梦想. 提交于 2019-11-30 08:41:20
I've got a problem. I'm writing a benchmark and I have a function than is either done in 2 seconds or after ~5 minutes(depending on the input data). And I would like to stop that function if it's executed for more than 3 seconds... How can I do it? Thanks a lot! The best way would be that your function can check its execution time often enough to decide to stop it it takes too long. If this is not the case, then run the function in a separate thread. In your main thread start a 3 seconds timer. When timer elapses, kill the separate thread using Thread.Abort() (of course unless the function is