B4J Question PyBridge in long running apps

Chris2

Active Member
Licensed User
Longtime User
I'm starting to play with PyBridge and in particular am using the Windows 10/11 Notifications example.
I intend to use this in a non-ui app that runs in the backgroung and generates a Windows Notification if/when it receives certain websocket messages.

This has lead me to have a few linked questions about the best use of the PyBridge connection in a long-running app (I apologise in advance if this is covered somewhere I've missed)...

1. Should the PyBridge connection be treated as something that can break periodically in a long running app (like a websocket connection for example)?
Hence, should the Py_Disconnected event be used to restart it?

2. In the kind of app described above, should the PyBridge connection be started once at app start and each notification be generated using the same connection, or should an individual PyBridge connection be Initialized/Started/Killed for every windows notification that is generated?
I instinctively want to do the latter, but wonder if multiple PyBridge connections can be alive at the same time?

Many thanks.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
PyBridge can run "forever" without breaking. Example: https://b4x.com:51041/barcodegenerator/index.html

I do recommend restarting it if it got disconnected (for example the user killed the Python process):
B4X:
Private Sub py_Disconnected
    Log("PyBridge disconnected!!!")
    Sleep(60000)
    Start 'the code that initialized Py and calls Start is here.
End Sub
 
Upvote 0
Solution
Top