Skip to content

Stuck when output exceeds 64KB #313

@xfangfang

Description

@xfangfang

Describe the bug

I have a script developed in python that may output a large amount of content.

It works normally on Xbar. When I switch to SwiftBar, I find that the program always displays three points as placeholders at startup.

When I check the process(ps -ef | grep *.py), I found that the script was running, but when I use run in Terminal..., it quickly produce output.

By manually interrupting the script, I get an error message on the status bar. The content of the message is what I originally wanted to output, but it is only 64KB long.

To Reproduce

Run any script that produces more than 64KB of content.

Expected behavior

Output longer content

Screenshots

Environment:

  • macOS version: 12.3
  • SwiftBar version: 1.4.3 (422)

Plugin Example:

#!/usr/bin/env /usr/bin/python3

# every menu item got 1KB size
LARGE_DATA = "*"*(1024-len("content 00 | extra="))

print("Long Content")
print("---")
# after changing 64 to 63, the problem disappears
for i in range(64):
    print(f"content {i:0>2} | extra={LARGE_DATA}")

Additional Context:

  • I don't run Bartender/Dozer/etc. or tested the issue without it running

guard streamOutput else { // horrible hack, code below this guard doesn't work reliably and I can't fugire out why.
do {
try run()
} catch {
os_log("Failed to launch plugin", log: Log.plugin, type: .error)
let data = outputPipe.fileHandleForReading.readDataToEndOfFile()
let errorData = errorPipe.fileHandleForReading.readDataToEndOfFile()
throw ShellOutError(terminationStatus: terminationStatus, errorData: errorData, outputData: data)
}
waitUntilExit()
outputData = outputPipe.fileHandleForReading.readDataToEndOfFile()
errorData = errorPipe.fileHandleForReading.readDataToEndOfFile()

I guess the problem is that the default buffer size is only 64KB. When the output content is too large, the program will get stuck at line 82, so I adjusted the above code(line 82 to 85) to:

  
             outputData = outputPipe.fileHandleForReading.readDataToEndOfFile() 
             errorData = errorPipe.fileHandleForReading.readDataToEndOfFile() 

             waitUntilExit() 

Then the program can run normally.

Ralated issue: #294

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions