Coder Social home page Coder Social logo

Comments (12)

Elektordi avatar Elektordi commented on May 29, 2024 1
[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.

Elektordi avatar Elektordi commented on May 29, 2024 1

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.

Elektordi avatar Elektordi commented on May 29, 2024

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.

aaarghhh avatar aaarghhh commented on May 29, 2024

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.

Elektordi avatar Elektordi commented on May 29, 2024

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.

aaarghhh avatar aaarghhh commented on May 29, 2024

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.

aaarghhh avatar aaarghhh commented on May 29, 2024

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.

aaarghhh avatar aaarghhh commented on May 29, 2024

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.

aaarghhh avatar aaarghhh commented on May 29, 2024

On my WIN machine seem fixed!! Thank you !

from obs-websocket-py.

Elektordi avatar Elektordi commented on May 29, 2024

Cool! Tell me if it fixes the problem on your linux box too, if yes I'll merge the branch.

from obs-websocket-py.

aaarghhh avatar aaarghhh commented on May 29, 2024

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.

Elektordi avatar Elektordi commented on May 29, 2024

You're welcome!

Fix merged to master.

from obs-websocket-py.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.