Code Monkey home page Code Monkey logo

Comments (6)

HelloZeroNet avatar HelloZeroNet commented on May 7, 2024
  • queue for websocket messages

from zeronet.

shakna-israel avatar shakna-israel commented on May 7, 2024

Would async managing this be able to help? Or is it because the greenlets are trying to attach to the same socket?

from zeronet.

HelloZeroNet avatar HelloZeroNet commented on May 7, 2024

It happened when i ran the zeronet on remote machine (around ~40ms away) and downloaded a site with many small files.
The ZeroNet pushes pushes an event over websocket after every file download, and maybe the last event message was still not finished when the next came.
I think it could be fixed like this:

def send(message):
 self.message_queue.append(message)
 if not self.sending:
    self.sending = True
    while self.message_queue:
      self.socket.send(self.message_queue.pop(0))
    self.sending = False

Maybe there is a better solution with gevent, but i like pure-python solutions, its easier to understand whats really happening.
Btw I optimized the Websocket to much smaller event messages, maybe its not an issue anymore, im going to test it later.

from zeronet.

nathantym avatar nathantym commented on May 7, 2024

The gevent queue is as understandable as a straight python implemented queue and it seems easy to use.

http://www.gevent.org/gevent.queue.html

one example they use at the bottom:

def worker():
    while True:
        item = q.get()
        try:
            do_work(item)
        finally:
            q.task_done()

q = JoinableQueue()
for i in range(num_worker_threads):
     gevent.spawn(worker)

for item in source():
    q.put(item)

q.join()  # block until all tasks are done

from zeronet.

HelloZeroNet avatar HelloZeroNet commented on May 7, 2024

I think this model will not work in this case, because we dont want to send messages in parallel and we dont want to wait until the message is sent

from zeronet.

HelloZeroNet avatar HelloZeroNet commented on May 7, 2024

ran into this problem again, so i fixed it:

def send(self, message, cb = None):

from zeronet.

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.