0

Basically I want to write a piece of code in threads (i.e. I need to execute the function for each object of the class)

My basic functionality is given as

def run(self):
    while True:
        functionCall() #This is a function which uses network, so it might take variable amount of time

But What I want to do is

def run(self):
    while True:
        # Try executing the below for N milli seconds
        functionCall()
        #else execute the below block
        timeoutCall()

I know I can do it with the help of SIGALARM in case of the wait time is in seconds. but unfortunately. I can spend only less time waiting(in milliseconds).Hoping for a good method to do it.

Thanks in advance

NSK
  • 180
  • 2
  • 12
  • How are you making those network requests? Any reasonable framework should provide some way to set an explicit timeout for it instead of relying on the OS to disconnect it. This will be much easier than trying to cancel it from outside. – Numerlor Feb 03 '22 at 14:43

1 Answers1

0

signal.settimer() accepts float value, maybe check that out.

You may find this thread to be helpful.