Comments (12)
[elektordi@gg7 ~]$ pip3 freeze |grep socket
obs-websocket-py==0.5
requests-unixsocket==0.1.5
websocket-client==0.57.0
But I also work with Django on others projets, and I had many problems with a scheduler on one. I finally discover it came from Django multi-thread architecture, my jobs were started multiple times at the same moment. I finally fixed using this "if":
def init():
if os.environ.get('RUN_MAIN', None) != "true":
return
scheduler = BackgroundScheduler()
scheduler.add_job(job_daily_report, 'cron', hour=7, minute=0)
scheduler.start()
logger.info('Scheduler has been started!')
init()
was called by ready(self) in my AppConfig (file apps.py)
Maybe it can help you...
from obs-websocket-py.
Oh, thanks for the traceback, I can see the problem is on the receiving thread!
I think the problem is threads being handled differently because of APScheduler... The receiving is not interrupted correctly...
Could you try the branch bugfix-32 I just pushed? It should ignore OS exceptions during socket disconnection.
from obs-websocket-py.
I think you are trying to send data over an already disconnected socket... It is possible to have a simple standalone script which shows the problem?
from obs-websocket-py.
Sure , you can check this simple POC.
https://gist.github.com/aaarghhh/2d2cdcd5e47d84e848b70fe4dd772cd6
I placed a delay before the disconnect and I try do isolate every connection in order to avoid some socket reusage.
Let me know what do you think.
from obs-websocket-py.
You can enable debug by putting that at the start of your script:
import logging
logging.basicConfig(level=logging.DEBUG)
And I also had to change your main to prevents the scheduler from stopping:
def main():
while True:
time.sleep(1)
And I got no exception, scenes were changing!
But you are indeed connecting and disconnecting very quickly, it's not a good thing. You should do something like that:
def setScene(websocket, sceneName):
websocket.call(requests.SetCurrentScene(sceneName))
def testjob():
ws = createOBSWS()
ws.connect()
setScene(ws, "Test")
setText(ws, "TESTSOBJ1", "TESTSCENE", "Hello")
setText(ws, "TESTSOBJ2", "TESTSCENE", "World!")
ws.disconnect()
I didn't include others methods, but that's the idea... I let you try that!
from obs-websocket-py.
Yes, you are right.
I copypasted my code in a main file, I forgot the loop. .
I'll try to a new level of LOG, I want to tell you that this engine is running inside a Django project. So the scheduler is started inside the Django startup.
I also refactored any job in order to connect and disconnect one time per job without instantiate it every call.
This issue is happening in a random way.
Seems that it's related to a time/resource limit. ( I was thinking to socket open or a disconnect during a call ..
May ask you what version of python /socket/ websocket are you running?
from obs-websocket-py.
uhm , in my Debian machine I haven't requests-unixsocket... ( OK ,realized now that is a grep outside your venv ) sorry...
For Django I used the same approach during the ready of a custom AppConfig, with the same flag on 'RUN_MAIN' to trigger it only once.
from obs-websocket-py.
I think the exception is happening during the disconnection phase...
DEBUG:obswebsocket.core:Sending message id 7: {'source': 'COUNTER', 'align': 'Loading', 'bk-color': None, 'bk-opacity': None, 'chatlog': None, 'chatlog_lines': None, 'color': None, 'extents': None, 'extents_cx': None, 'extents_cy': None, 'file': None, 'read_from_file': None, 'font': None, 'font.face': None, 'font.flags': '0', 'font.size': None, 'font.style': None, 'gradient': None, 'gradient_color': None, 'gradient_dir': None, 'gradient_opacity': None, 'outline': None, 'outline_color': None, 'outline_size': None, 'outline_opacity': None, 'text': None, 'valign': None, 'vertical': None, 'render': None, 'request-type': 'SetTextGDIPlusProperties', 'message-id': '7'}
DEBUG:obswebsocket.core:Got answer for id 7: {'error': "specified source doesn't exist", 'message-id': '7', 'status': 'error'}
INFO:obswebsocket.core:Disconnecting...
Exception in thread Thread-85:
Traceback (most recent call last):
File "XXXXXXXXXXXXXXXXXXAppData\Local\Programs\Python\Python36-32\lib\threading.py", line 916, in _bootstrap_inner
self.run()
File "XXXXXXXXXXXXXXXXXXDocuments\Progetti\Python\ZZZZZZZZ\YYYYYYYY\venv\lib\site-packages\obswebsocket\core.py", line 226, in run
message = self.ws.recv()
File "XXXXXXXXXXXXXXXXXXDocuments\Progetti\Python\ZZZZZZZZ\YYYYYYYY\venv\lib\site-packages\websocket\_core.py", line 314, in recv
opcode, data = self.recv_data()
File "XXXXXXXXXXXXXXXXXXDocuments\Progetti\Python\ZZZZZZZZ\YYYYYYYY\venv\lib\site-packages\websocket\_core.py", line 331, in recv_data
opcode, frame = self.recv_data_frame(control_frame)
File "XXXXXXXXXXXXXXXXXXDocuments\Progetti\Python\ZZZZZZZZ\YYYYYYYY\venv\lib\site-packages\websocket\_core.py", line 358, in recv_data_frame
self.send_close()
File "XXXXXXXXXXXXXXXXXXDocuments\Progetti\Python\ZZZZZZZZ\YYYYYYYY\venv\lib\site-packages\websocket\_core.py", line 391, in send_close
self.send(struct.pack('!H', status) + reason, ABNF.OPCODE_CLOSE)
File "XXXXXXXXXXXXXXXXXXDocuments\Progetti\Python\ZZZZZZZZ\YYYYYYYY\venv\lib\site-packages\websocket\_core.py", line 253, in send
return self.send_frame(frame)
File "XXXXXXXXXXXXXXXXXXDocuments\Progetti\Python\ZZZZZZZZ\YYYYYYYY\venv\lib\site-packages\websocket\_core.py", line 279, in send_frame
l = self._send(data)
File "XXXXXXXXXXXXXXXXXXDocuments\Progetti\Python\ZZZZZZZZ\YYYYYYYY\venv\lib\site-packages\websocket\_core.py", line 449, in _send
return send(self.sock, data)
File "XXXXXXXXXXXXXXXXXXDocuments\Progetti\Python\ZZZZZZZZ\YYYYYYYY\venv\lib\site-packages\websocket\_socket.py", line 157, in send
return _send()
File "XXXXXXXXXXXXXXXXXXDocuments\Progetti\Python\ZZZZZZZZ\YYYYYYYY\venv\lib\site-packages\websocket\_socket.py", line 139, in _send
return sock.send(data)
OSError: [WinError 10038] Tentativo di operazione su un elemento diverso dal socket
I'll try on my Debian machine.
from obs-websocket-py.
On my WIN machine seem fixed!! Thank you !
from obs-websocket-py.
Cool! Tell me if it fixes the problem on your linux box too, if yes I'll merge the branch.
from obs-websocket-py.
Tested for one day, my service seems stable, so the exception wasn't raised anymore on WIN/LINUX . Again thank you a lot.
from obs-websocket-py.
You're welcome!
Fix merged to master.
from obs-websocket-py.
Related Issues (20)
- MessageTimeout HOT 3
- No support for calling Virtual Camera on and off? HOT 1
- Refresh browers source, Control media audio mute and unmute, control filter visible, hide or show HOT 1
- Not able to connect to the websocket HOT 2
- Request: ExecuteBatch
- Handling error when OBS closes before script HOT 4
- Not working with OBS 28.0.0 (obs-websocket v5) HOT 2
- How to add image source in scene? HOT 2
- Do merge and update to websocket 5.0 HOT 2
- Remote Python2 compatiblity
- Getting KeyError: 'status' while trying to connect to OBS studio HOT 2
- Switch Scene v4 Sample HOT 5
- KeyError: 'status' with OBS 29 and obs-websocket-py 0.5.3 HOT 4
- SetSourceSettings expects one argument but 3 were given HOT 4
- Error not understood on scene change. HOT 4
- ConnectionRefusedError: Unable to make OBS and obs-websocket-py cooperate HOT 1
- requests.SetRecordDirectory takes 1 positional argument but 2 were given HOT 6
- How I can get the value of an call request? HOT 3
- Adding timeout to obsws_python.EventClient() causes timeout even when connection is ok HOT 2
- GetStreamStatus Inputdata and outputdata mix up
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from obs-websocket-py.