benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 9fb1b806-4632-56c6-a443-28751b913a57

Problem

Answer published by the source. Consult the official source to check your work against its answer.

complete prompt

import subprocess
import os
import threading

def task_func(script_path: str, timeout: int = 60) -> str:
    """
    Execute a specified python code with a given timeout. If the script execution exceeds the timeout, it is terminated.

    Parameters:
    - script_path (str): The path to the Python code to be executed.
    - timeout (int): The maximum allowed time (in seconds) for the script execution. Default is 60 seconds.

    Returns:
    - str: A message indicating if the code was terminated due to timeout or executed successfully. The message is either "Script executed successfully." or "Terminating process due to timeout."

    Requirements:
    - subprocess
    - os
    - threading

    Examples:
    >>> task_func('/pathto/MyrScript.py')
    'Script executed successfully.'
    
    >>> task_func('/pathto/LongRunningScript.py', 30)
    'Terminating process due to timeout.'

    Note:
    - If the script was terminated due to timeout it will return "Script executed successfully.", otherwise "Terminating process due to timeout."

    Raise:
    - The code will raise FileNotFoundError if the file is not exist.
    """

instruct prompt

Execute a specified python code with a given timeout. If the script execution exceeds the timeout, it is terminated. >>> task_func('/pathto/LongRunningScript.py', 30) 'Terminating process due to timeout.' Raise: - The code will raise FileNotFoundError if the file is not exist.
Note that: If the script was terminated due to timeout it will return "Script executed successfully.", otherwise "Terminating process due to timeout."
The function should output with:
    str: A message indicating if the code was terminated due to timeout or executed successfully. The message is either "Script executed successfully." or "Terminating process due to timeout."
You should write self-contained code starting with:

Code

import subprocess
import os
import threading
def task_func(script_path: str, timeout: int = 60) -> str:

code prompt

Code

import subprocess
import os
import threading
def task_func(script_path: str, timeout: int = 60) -> str:

entry point

task_func

libs

  • subprocess
  • threading
  • os

Discussion

Discussion

No discussion posts on this page yet. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.

See answer Answer published by the source

Artifacts

Code, notes and reproducible work shared by participants. Files are served from a separate origin.

No artifacts on this page yet. Share reproducible code or notes in a contribution. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.

Source and history

Official source

initial import