# How to achieve a function that runs every 10 seconds

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-achieve-a-function-that-runs-every-10-seconds%2F32830%3E%5C
**Category:** 🔒 Gradio\
**Created:** [March 1, 2023, 6:06pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-achieve-a-function-that-runs-every-10-seconds%2F32830 "2023-03-01T18:06:22Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![LittleWing](https://avatars.discourse-cdn.com/v4/letter/l/4af34b/32.png) [@LittleWing](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FLittleWing)%5C
**Post date:** [March 1, 2023, 6:06pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-achieve-a-function-that-runs-every-10-seconds%2F32830%2F1 "2023-03-01T18:06:22Z")

</div>

Hi,

I’m trying to achieve a function that runs every 10 seconds with `every`  
I highlighted what row of the code that I want to use `every`

this is my GUI:

> ###Gradio GUI###  
> with gr.Blocks(title = ‘IPBlocker’) as switches\_ver:  
> gr.Markdown(‘Welcome to IPBlocker’)  
> with gr.Row():  
> fg\_names = [‘DCDR Status’,‘TLV Status’,‘HFA Status’, ‘KRML Status’]  
> for name in fg\_names:  
> **gr.Textbox(value = threat\_feed\_check(name), label = name, interactive=False, every=10)**  
> with gr.Tab(label = ‘IPBlocker’):  
> with gr.Row():  
> with gr.Column():  
> ips\_to\_block = gr.Textbox(label = “IPs”, lines = 10, placeholder=(‘Please fill Ips to block’))  
> block\_btn = gr.Button(‘Block’)  
> with gr.Row():  
> ip\_look\_up\_btn = gr.Button('Look for IP or URL: ')  
> look\_up = gr.Textbox(show\_label=False)  
> with gr.Row():  
> ip\_removal\_btn = gr.Button(‘Remove IP:’)  
> remove = gr.Textbox(show\_label=False)
> 
> ```
> with gr.Column():
> output_textbox = gr.Textbox(label = "Results", lines=10)
> with gr.Row():
> current_commit_stats = gr.Textbox(label = 'Current IP\s or URLs added to block:')
> forti_ips_stats = gr.Textbox(label = 'Total blocked IP\s on Fortigate: ')
> forti_urls_stats = gr.Textbox(label = 'Total URLs blocked on Fortigate')
> forti_total_stats = gr.Textbox(label = 'Total blocked IP\s and URLs on Fortigate')
> block_btn.click(fn=block_ip, inputs = ips_to_block, outputs = [output_textbox, current_commit_stats, forti_ips_stats, forti_urls_stats, forti_total_stats])
> ip_look_up_btn.click(fn=ip_look_up, inputs = look_up, outputs = look_up)
> ip_removal_btn.click(fn=ip_removal, inputs = remove, outputs = remove)
> 
> ```
> 
> switches\_ver.queue().launch()

My function:

```auto

def threat_feed_check(threat_feed):

    if threat_feed == 'DCDR Status':
        response = requests.get('https://192.168.1.1/api/v2/monitor/system/external-resource/entry-list?mkey=Domain_Blocker&vdom=root', headers=headers, verify=False)
        print('Trying')

        return response.json()['results']
        
    if threat_feed == 'TLV Status':
        response = requests.get('https://192.168.1.2/api/v2/monitor/system/external-resource/entry-list?mkey=Domain_Blocker&vdom=root', headers=headers, verify=False)
        
        return response.json()['results']
    if threat_feed == 'HFA Status':
        response = requests.get('https://192.168.1.3/api/v2/monitor/system/external-resource/entry-list?mkey=Domain_Blocker&vdom=root', headers=headers, verify=False)

        return response.json()['results']
        
    if threat_feed == 'KRML Status':
        response = requests.get('https://192.168.1.4/api/v2/monitor/system/external-resource/entry-list?mkey=Domain_Blocker&vdom=root', headers=headers, verify=False)
        
        return response.json()['results']

```

Any Idea why It doesn’t work?

Thank you!

---

<div class="post-metadata">

**Author:** ![freddyaboulton](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/freddyaboulton/32/32732_2.png) [@freddyaboulton](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Ffreddyaboulton)%5C
**Post date:** [March 1, 2023, 6:30pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-achieve-a-function-that-runs-every-10-seconds%2F32830%2F2 "2023-03-01T18:30:43Z")

</div>

What’s not working @LittleWing ?

---

<div class="post-metadata">

**Author:** ![LittleWing](https://avatars.discourse-cdn.com/v4/letter/l/4af34b/32.png) [@LittleWing](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FLittleWing)%5C
**Post date:** [March 1, 2023, 6:49pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-achieve-a-function-that-runs-every-10-seconds%2F32830%2F3 "2023-03-01T18:49:39Z")

</div>

Oh,  
The function `threat_feed_check` doesn’t run every 10 seconds

---

<div class="post-metadata">

**Author:** ![freddyaboulton](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/freddyaboulton/32/32732_2.png) [@freddyaboulton](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Ffreddyaboulton)%5C
**Post date:** [March 1, 2023, 7:16pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-achieve-a-function-that-runs-every-10-seconds%2F32830%2F4 "2023-03-01T19:16:26Z")

</div>

Is it running approximately every 10 seconds or it’s not running repeatedly at all?

What version of gradio are you using?

---

<div class="post-metadata">

**Author:** ![LittleWing](https://avatars.discourse-cdn.com/v4/letter/l/4af34b/32.png) [@LittleWing](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FLittleWing)%5C
**Post date:** [March 1, 2023, 7:18pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-achieve-a-function-that-runs-every-10-seconds%2F32830%2F5 "2023-03-01T19:18:45Z")

</div>

Doesn’t run repeatedly - Only once when I run the script.  
version: 3.19.1

---

<div class="post-metadata">

**Author:** ![freddyaboulton](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/freddyaboulton/32/32732_2.png) [@freddyaboulton](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Ffreddyaboulton)%5C
**Post date:** [March 1, 2023, 7:43pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-achieve-a-function-that-runs-every-10-seconds%2F32830%2F6 "2023-03-01T19:43:57Z")

</div>

> [@LittleWing](#):
>
> **gr.Textbox(value = threat\_feed\_check(name), label = name, interactive=False, every=10)**

The value of the textbox must be callable, so I think rewriting `threat_feed_check` to return a function should be work

```python
def threat_feed_check(threat_feed):
    def inner():
      if threat_feed == 'DCDR Status':
          response = requests.get('https://192.168.1.1/api/v2/monitor/system/external-resource/entry-list?mkey=Domain_Blocker&vdom=root', headers=headers, verify=False)
          print('Trying')
  
          return response.json()['results']
          
      if threat_feed == 'TLV Status':
          response = requests.get('https://192.168.1.2/api/v2/monitor/system/external-resource/entry-list?mkey=Domain_Blocker&vdom=root', headers=headers, verify=False)
          
          return response.json()['results']
      if threat_feed == 'HFA Status':
          response = requests.get('https://192.168.1.3/api/v2/monitor/system/external-resource/entry-list?mkey=Domain_Blocker&vdom=root', headers=headers, verify=False)
  
          return response.json()['results']
          
      if threat_feed == 'KRML Status':
          response = requests.get('https://192.168.1.4/api/v2/monitor/system/external-resource/entry-list?mkey=Domain_Blocker&vdom=root', headers=headers, verify=False)
          
          return response.json()['results']
     return inner

```

The indentation got a bit messed up but hopefully you get what I mean.

---

<div class="post-metadata">

**Author:** ![LittleWing](https://avatars.discourse-cdn.com/v4/letter/l/4af34b/32.png) [@LittleWing](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FLittleWing)%5C
**Post date:** [March 1, 2023, 8:05pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-achieve-a-function-that-runs-every-10-seconds%2F32830%2F7 "2023-03-01T20:05:17Z")

</div>

Thank you.

I apologize for misunderstanding the docs, I know it says value must be callable, I was thinking that callable must mean just a function that the component will run every 10 seconds.

Its working as it should now.

I really appreciate your time helping me.

---

<div class="post-metadata">

**Author:** ![freddyaboulton](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/freddyaboulton/32/32732_2.png) [@freddyaboulton](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Ffreddyaboulton)%5C
**Post date:** [March 1, 2023, 8:28pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-achieve-a-function-that-runs-every-10-seconds%2F32830%2F8 "2023-03-01T20:28:02Z")

</div>

No need to apologize! Glad it’s working now
