How to efficiently do many tasks a “little later” in Python?

后端 未结 10 933
心在旅途
心在旅途 2021-01-30 11:59

I have a process, that needs to perform a bunch of actions \"later\" (after 10-60 seconds usually). The problem is that those \"later\" actions can be a lot (1000s), so using a

10条回答
  •  时光取名叫无心
    2021-01-30 12:27

    Presuming your process has a run loop which can receive signals and the length of time of each action is within bounds of sequential operation, use signals and posix alarm()

        signal.alarm(time)
    If time is non-zero, this function requests that a 
    SIGALRM signal be sent to the process in time seconds. 
    

    This depends on what you mean by "those "later" actions can be a lot" and if your process already uses signals. Due to phrasing of the question it's unclear why an external python package would be needed.

提交回复
热议问题