Skip to content

Commit 745e1fd

Browse files
committed
add ability to run processing in seperate thread
1 parent 4ea85b1 commit 745e1fd

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

easy_nano/lib.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import decimal
22
import json
33
import warnings
4+
import threading
45
from typing import Optional, Dict
6+
from functools import partial
57

68
import requests
79
from nanolib import (
@@ -70,7 +72,7 @@ def _get_account_info(self, account_address: str):
7072
data = {"balance": 0}
7173
return data
7274

73-
def receive(self, count: Optional[int] = 5):
75+
def receive(self, count: Optional[int] = 5, process_in_thread: bool = False):
7476
data = self._call_node_url(
7577
{"action": "pending", "account": self.public_address, "count": count}
7678
)
@@ -84,7 +86,18 @@ def receive(self, count: Optional[int] = 5):
8486
account_info = self._get_account_info(self.public_address)
8587
total_amount = amount + int(account_info["balance"])
8688
print(f"Received {mnano_amount} nano from {block_addr}. Processing...")
87-
block_hash = self._receive_block(block_hash, total_amount, is_raw=True)
89+
if process_in_thread:
90+
t = threading.Thread(
91+
target=partial(
92+
self._receive_block,
93+
link=block_hash,
94+
amount=total_amount,
95+
is_raw=True,
96+
)
97+
)
98+
t.start()
99+
else:
100+
self._receive_block(block_hash, total_amount, is_raw=True)
88101
ret_data[block_addr] = {
89102
"amount": mnano_amount,
90103
"hash": block_hash,

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
setup(
44
name="easy_nano",
55
packages=["easy_nano"],
6-
version="4",
6+
version="5",
77
license="MIT",
88
description="Send & recieve nano without the fuss",
99
author="Micah Price",
1010
author_email="98mprice@gmail.com",
1111
url="https://github.com/micah5",
12-
download_url="https://github.com/micah5/easy_nano/archive/refs/tags/v_4.tar.gz",
12+
download_url="https://github.com/micah5/easy_nano/archive/refs/tags/v_5.tar.gz",
1313
keywords=["nano"],
1414
install_requires=["requests", "PyQRCode", "click", "nanolib"],
1515
classifiers=[

0 commit comments

Comments
 (0)