invisibleroads / invisibleroads/socketIO-client

How to properly implement an async pub/sub client?

Open
#80 7 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
441
Forks
204
PR merge metrics
No merged PRs in 30d

Description

I have the following solution but it does not work very well. It does not seem to disconnect and is very slow on joining.

```
#!/usr/bin/env python

import time
import threading
from socketIO_client import SocketIO

class TestSubscribe():

def connect(self):
baseurl = "http://v1.livenet.bitcoin.chromanode.net"
self._socketIO = SocketIO(baseurl, 80)
self._socketIO.on('new-block', self.on_newblock)
self._socketIO.emit('subscribe', 'new-block')
self._socketIO_thread = threading.Thread(target=self._socketIO.wait)
self._socketIO_thread.start()

def on_newblock(self, blockid, blockheight):
print "new-block:", blockid, blockheight
# add to input queue for further processing

def disconnect(self):
# XXX works ... badly
print "disconnect before:", self._socketIO.connected
self._socketIO.disconnect()
self._socketIO_thread.join() # takes quite some time
print "disconnect after:", self._socketIO.connected # still connected?
self._socketIO = None
self._socketIO_thread = None

testsubscribe = TestSubscribe()
testsubscribe.connect()
time.sleep(10)
testsubscribe.disconnect()
```
##

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.