Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stuck when output exceeds 64KB #313

Closed
1 task done
xfangfang opened this issue Apr 26, 2022 · 3 comments
Closed
1 task done

Stuck when output exceeds 64KB #313

xfangfang opened this issue Apr 26, 2022 · 3 comments
Milestone

Comments

@xfangfang
Copy link
Contributor

xfangfang commented Apr 26, 2022

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

@melonamin
Copy link
Contributor

Hey @xfangfang, thank you, your assesment is correct, I've got to this point as well when was researching #294
The problem is I couldn't find any buffer configuration options, yet.

so I adjusted the above code(line 82 to 85)

This is an interesting idea, I was editing this code so much and got a little blindspoted, thank you for suggestion, I'll test.

@melonamin melonamin added this to the 1.4.4 milestone May 1, 2022
@melonamin
Copy link
Contributor

melonamin commented May 1, 2022

Implemented in this beta build

@xfangfang
Copy link
Contributor Author

@melonamin Great! It works fine for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants