question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

multiprocessing.Process fetch_trade: 'luno' object has no attribute 'publicGetTickers'

See original GitHub issue

Hi I’m trying to spawn a process for each of a number of exchanges, and testing with a single one for now, just to get the Multiprocessing working. However, it is failing.

import ccxt
import multiprocessing

if __name__ == '__main__':
    exchange_class = getattr(ccxt, 'luno')
    exchange = exchange_class()
    a_process = multiprocessing.Process(target=exchange.fetch_trades, args=('BTC/ZAR', 1553983200000))
    a_process.start()

fails with

AttributeError: 'luno' object has no attribute 'publicGetTickers'

Any way to fix this? If not, any alternatives?

Environment info:

  • OS: Win 10, 64 bit
  • Programming Language version: Python 3.7.2
  • CCXT version: 1.18.398
  • Exchange: luno
  • Method: fetch_trades(), via multiprocessing.Process()

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
kroitorcommented, Apr 4, 2019

@ErnstDinkelmann

Can you confirm that the above will not break your rate-limiting (or other stuff) since only one instance of any class used at any one time?

The above code doesn’t use the rate-limiter, it is off by default and has to be enabled as described in the Manual: https://github.com/ccxt/ccxt/wiki/Manual#rate-limit

If you’re creating one process per exchange, i’d suggest that you rather pass the exchange name to the process, and create the exchange instance inside the worker subprocess:

def worker_function(exchange_id, *args):
    exchange = getattr(ccxt, exchange_id)({'enableRateLimit': True})
    result = exchange.fetch_trades(*args)
    print(result)

if __name__ == '__main__':
    lst_processes = []
    for exchange_id in lst_exchangeids:
        lst_processes.append(multiprocessing.Process(target=worker_function, args=(exchange_id, 'BTC/USD', 1553983200000)))

    for one_process in lst_processes:
        one_process.start()

Does that work for you? (pardon, didn’t have the time to actually test it throughly yet)

1reaction
ErnstDinkelmanncommented, Apr 4, 2019

Yes, aware of default being false, sorry, just removed that code in the example.

I’m happy with the solution provided.

I guess some further thinking would be required if one wants to fetch trade data with multiple processes, and at the same time execute trades on one or more of the exchanges. I guess this would require rate-limiting to be implemented in the application to be safe.

You are welcome to close this issue. Thank you both.

Read more comments on GitHub >

github_iconTop Results From Across the Web

yet another confusion with multiprocessing error, 'module ...
The spawn based approach is to either launch a fresh process and import the main module (but not as __main__ , to prevent...
Read more >
multiprocessing — Process-based parallelism — Python 3.11 ...
Introduction. multiprocessing is a package that supports spawning processes using an API similar to the threading module. The multiprocessing package offers ...
Read more >
multiprocessing Basics - Python Module of the Week - PyMOTW
The simplest way to spawn a second is to instantiate a Process object with a target function and call start() to let it...
Read more >
Share Object Instance Attributes With Processes in Python
You can share process class attributes via multiprocessing.Value and multiprocessing.Array instances. In this tutorial you will discover how to ...
Read more >
multiprocessing Attribute Error - Esri Community
File "C:\Python26\ArcGIS10.0\lib\multiprocessing\process.py", line 232, ... AttributeError: 'module' object has no attribute'project'.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found