Skip to main content

Python timeframe tool for time monitoring for each event, error handling, traceback recording...

Project description

timeframe

Python timeframe tool for time monitoring for each event, error handling, traceback recording...

Downloads Downloads Downloads PyPI version

How to install

pip install timeframe-event

You can also copy timeframe.py from GitHub and drop it in your project

This project/file only uses standard libraries so installation of additional dependency is not required

Example

import random, time
from timeframe import TimeFrame
async def func(timeframe: TimeFrame, *args, **kwargs): # Create rt(realtime) function 
    timeframe.print_mono()
    print(args, kwargs)
    

with TimeFrame('test args', name='Text request', rt=func, test_kwargs='test kwargs') as time_frame:
    with time_frame.create(name='Prompt') as group_prompt:
        with group_prompt.create(name='Prompt request', retries=5, ignore_retries=(TimeoutError,)) as event_frame:
            function_call = False
            for frame in event_frame:
                async with frame:
                    time.sleep(random.uniform(0, 0.4))  # Stimulate doing network operation
                    if random.random() < 0.2:
                        raise ValueError  # Stimulate a complete random chance of a network error occur
                    if random.random() < 0.3:
                        raise TimeoutError # Stimulate a complete internet breakdown
                    if random.random() < 0.9:
                        function_call = True
        if function_call:
            with group_prompt.create(name='Function call `mul`', retries=0):
                time.sleep(random.uniform(0, 0.01))  # Stimulate doing network operation
            with group_prompt.create(name='Function Response', retries=5) as event_frame:
                for frame in event_frame:
                    async with frame:
                        time.sleep(random.uniform(0, 0.4))  # Stimulate doing network operation
                        if random.random() < 0.7:
                            raise ValueError  # Stimulate a complete random chance of a network error occur
>>> print(time_frame.traceback_format())
[596869.233s] Error raised on Attempt 'Attempt #1' from parent 'Prompt request' at TimeFrame 'Text request':
Traceback (most recent call last):

  File "...\timeframe.py", line 260, in test
    raise ValueError  # Stimulate a complete random chance of a network error occur
    ^^^^^^^^^^^^^^^^

ValueError

[596869.397s] Error raised on Attempt 'Attempt #2' from parent 'Prompt request' at TimeFrame 'Text request':
Traceback (most recent call last):

  File "...\timeframe.py", line 260, in test
    raise ValueError  # Stimulate a complete random chance of a network error occur
    ^^^^^^^^^^^^^^^^

ValueError

[596870.032s] Error raised on Attempt 'Attempt #1' from parent 'Function Response' at TimeFrame 'Text request':
Traceback (most recent call last):

  File "...\timeframe.py", line 271, in test
    raise ValueError  # Stimulate a complete random chance of a network error occur
    ^^^^^^^^^^^^^^^^

ValueError

[596870.171s] Error raised on Attempt 'Attempt #2' from parent 'Function Response' at TimeFrame 'Text request':
Traceback (most recent call last):

  File "...\timeframe.py", line 271, in test
    raise ValueError  # Stimulate a complete random chance of a network error occur
    ^^^^^^^^^^^^^^^^

ValueError
>>> print(time_frame.frame_format_dc(limit=1024)) #Character limit of discord embed field value
Total: 0001.252s (Total Frames: 11)
✅-Prompt (0001.252s)
> ⚠️-Prompt request (0000.607s)
> - ❌-Attempt #1 (0000.203s)
> - ❌-Attempt #2 (0000.164s)
> - ✅-Attempt #3 (0000.240s)
> ✅-Function call `mul` (0000.005s)
> ⚠️-Function Response (0000.640s)
> - ❌-Attempt #1 (0000.390s)
> - ❌-Attempt #2 (0000.139s)
> - ✅-Attempt #3 (0000.111s)

Example: image

>>> print(time_frame.frame_format_mono()) # Use of export as file or display on console
Total: 0001.252s (Total Frames: 11)
✅-Text request (0001.252s)
  ✅-Prompt (0001.252s)
    ⚠️-Prompt request (0000.607s)
      ❌-Attempt #1 (0000.203s)
      ❌-Attempt #2 (0000.164s)
      ✅-Attempt #3 (0000.240s)
    ✅-Function call `mul` (0000.005s)
    ⚠️-Function Response (0000.640s)
      ❌-Attempt #1 (0000.390s)
      ❌-Attempt #2 (0000.139s)
      ✅-Attempt #3 (0000.111s)
print(timeframe.frame_format_custom()) # Default with markdown

Total: 0000.826s (Total Frames: 11)

✅-Prompt (0000.826s)

  • ⚠️-Prompt request (0000.690s)
  • ❌-Attempt #1 (0000.135s)
  • ❌-Attempt #2 (0000.020s)
  • ❌-Attempt #3 (0000.126s)
  • ❌-Attempt #4 (0000.349s)
  • ✅-Attempt #5 (0000.060s)
  • ✅-Function call mul (0000.004s)
  • ✅-Function Response (0000.132s)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

timeframe-event-1.1.6.tar.gz (20.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

timeframe_event-1.1.6-py3-none-any.whl (19.2 kB view details)

Uploaded Python 3

File details

Details for the file timeframe-event-1.1.6.tar.gz.

File metadata

  • Download URL: timeframe-event-1.1.6.tar.gz
  • Upload date:
  • Size: 20.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.18

File hashes

Hashes for timeframe-event-1.1.6.tar.gz
Algorithm Hash digest
SHA256 1fe307e34e7f49677d537f96ce946b8252d8dbe38d48d05f94b4768553ee40a6
MD5 0f91b7f2cb05a10dc9f05bbe69c2c1e7
BLAKE2b-256 7ca2778f8b5a52c82b268e312396117dd9bb098bb522880e792ec7ddde67766f

See more details on using hashes here.

File details

Details for the file timeframe_event-1.1.6-py3-none-any.whl.

File metadata

File hashes

Hashes for timeframe_event-1.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 ad59b218d823cff185a0e8b13a7355aeaf6cec633bd83e021cf63cb800f9010b
MD5 45b7fd19420402c7b26462129b1b6962
BLAKE2b-256 bd968e9327cc4ddab6d94552cdebaafc3d91d35eef5540513bd12b4eb6418cd1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page