Comments (5)
Let's see if I understand you correctly:
You'd like to process the data that arrives in the btfxwss class in a parallel way, meaning simultaneously, correct?
In that case you'll only need a single btfxwss class. Then, start a Process (from the multiprocessing module) and give it a function that pulls data from the btfxwss properties and processes it.
from btfxwss.
Yes, you are right, that is exactly what i want.
I've tried the following:
import time
from multiprocessing import Process
from btfxwss import BtfxWss
key = 'abc'
secret = 'abc'
pair = 'BCHUSD'
def process_order_book(raw_books):
while True:
raw_orders = raw_books.get()
print(raw_orders)
if __name__ == '__main__':
wss = BtfxWss(key=key, secret=secret, log_level='DEBUG')
wss.start()
time.sleep(2)
wss.authenticate()
time.sleep(2)
wss.subscribe_to_raw_order_book(pair=pair, prec='R0', len='100')
time.sleep(2)
raw_books = wss.raw_books(pair=pair)
p1 = Process(target=process_order_book, kwargs={'raw_books': raw_books})
p1.start()
p1.join()
As you can see, I just print the raw books in new process. It works, but it prints only few first orders (messages from queue) and then it stucks on raw_books.get(). What am I doing wrong?
UPD:
But if I try to add the process manager:
import time
from multiprocessing import Process
from btfxwss import BtfxWss
from multiprocessing.managers import BaseManager
key = 'abc',
secret = 'abc'
pair = 'BCHUSD'
def process_order_book(_wss):
raw_books = _wss.raw_books(pair=pair)
while True:
raw_orders = raw_books.get()
print(raw_orders)
if __name__ == '__main__':
BaseManager.register('BtfxWss', BtfxWss)
manager = BaseManager()
manager.start()
wss = manager.BtfxWss(key=key, secret=secret, log_level='DEBUG')
wss.start()
time.sleep(2)
wss.authenticate()
time.sleep(2)
wss.subscribe_to_raw_order_book(pair=pair, prec='R0', len='100')
time.sleep(2)
p1 = Process(target=process_order_book, kwargs={'_wss': wss})
p1.start()
p1.join()
It gives me the userializable object Error:
Process Process-2:
Traceback (most recent call last):
File "/usr/lib/python3.5/multiprocessing/process.py", line 249, in _bootstrap
self.run()
File "/usr/lib/python3.5/multiprocessing/process.py", line 93, in run
self._target(*self._args, **self._kwargs)
File "/tmp.py", line 12, in process_order_book
raw_books = _wss.raw_books(pair=pair)
File "", line 2, in raw_books
File "/usr/lib/python3.5/multiprocessing/managers.py", line 732, in _callmethod
raise convert_to_error(kind, result)
multiprocessing.managers.RemoteError:
Unserializable message: ('#RETURN', <queue.Queue object at 0x7fd74fdf2518>)
from btfxwss.
UPD:
Ok, I got it.
After using multithreading, but NOT multiprocessing all works fine.
I think it's because of that the BtfxWss (and its properties) are not so easy serialazable and Python can not share objects between my processes. But threads have the common memory space, that's why threads work:
import time
import threading
from btfxwss import BtfxWss
key = 'abs',
secret = 'abs'
pair = 'BCHUSD'
def process_order_book(raw_books):
while True:
raw_orders = raw_books.get()
print(raw_orders)
threads = []
if __name__ == '__main__':
wss = BtfxWss(key=key, secret=secret, log_level='DEBUG')
wss.start()
time.sleep(2)
wss.authenticate()
time.sleep(2)
wss.subscribe_to_raw_order_book(pair=pair, prec='R0', len='100')
time.sleep(2)
raw_books = wss.raw_books(pair=pair)
t = threading.Thread(target=process_order_book, args=(raw_books,))
threads.append(t)
t.start()
from btfxwss.
Well, the issue with using the threading
module is that it doesn't actually process data in a parallel manner.
I could make use of multiprocessing.Queue
instead of queue.Queue
in a future release, that way you can pass the Queue
object accessed via the properties to truly parallel processes. Otherwise, I'm not convinced you'd gain much from using threading in this context.
But do let me know your findings!
from btfxwss.
I've spent some time yesterday to understand the difference between processes and threads and yes, you are right, it'll be not so much odds using a threads.
And I think, multiprocessing queues will be a really great feature =)
from btfxwss.
Related Issues (20)
- Timeout settings? HOT 1
- Websocket configuration is not restored during reconnect HOT 1
- pip install not newest version HOT 1
- after running for hours the timeout become much HOT 1
- Connection Issue HOT 2
- A proper handling of a Bitfinex-initiated connection closing
- how to reconnect properly HOT 3
- ORDER RELATED API HOT 1
- SUBSCRIPTION TO DATA HOT 1
- authenticated channels HOT 4
- New websocket-client release breaking code HOT 1
- client_tests don't work HOT 8
- problems with reconection HOT 3
- Pypi version 1.2.2 breaks `raise_exception` HOT 3
- websockets reconnecting constantly? HOT 2
- the auth_nonce problem
- fail to run client.py ,help HOT 2
- not responding sometimes
- Upcoming Bitfinex API Update June 2019
- Account channel not updated
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 btfxwss.