main.go 640 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package main
  2. import (
  3. "fmt"
  4. "time"
  5. "github.com/langgenius/dify-sandbox/internal/core/runner/python"
  6. "github.com/langgenius/dify-sandbox/internal/utils/log"
  7. )
  8. const python_script = `
  9. raise Exception("hello world")
  10. `
  11. func main() {
  12. runner := python.PythonRunner{}
  13. stdout, stderr, done, err := runner.Run(python_script, time.Second*10, nil)
  14. if err != nil {
  15. log.Panic("failed to run python script: %v", err)
  16. }
  17. for {
  18. select {
  19. case <-done:
  20. return
  21. case out := <-stdout:
  22. if string(out) != "" {
  23. fmt.Println(string(out))
  24. }
  25. case err := <-stderr:
  26. if string(err) != "" {
  27. fmt.Println(string(err))
  28. }
  29. }
  30. }
  31. }