Browse Source

use functools.wraps() for some wrappers

to help debugging
patch-4
SomberNight 4 years ago
parent
commit
ff485cee62
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 9
      electrum/interface.py
  2. 3
      electrum/lnpeer.py
  3. 3
      electrum/util.py

9
electrum/interface.py

@ -35,6 +35,7 @@ from ipaddress import IPv4Network, IPv6Network, ip_address, IPv6Address, IPv4Add
import itertools
import logging
import hashlib
import functools
import aiorpcx
from aiorpcx import TaskGroup
@ -375,10 +376,13 @@ class Interface(Logger):
# Dump network messages (only for this interface). Set at runtime from the console.
self.debug = False
asyncio.run_coroutine_threadsafe(
self.network.taskgroup.spawn(self.run()), self.network.asyncio_loop)
self.taskgroup = SilentTaskGroup()
async def spawn_task():
task = await self.network.taskgroup.spawn(self.run())
task.set_name(f"interface::{str(server)}")
asyncio.run_coroutine_threadsafe(spawn_task(), self.network.asyncio_loop)
@property
def host(self):
return self.server.host
@ -476,6 +480,7 @@ class Interface(Logger):
return sslc
def handle_disconnect(func):
@functools.wraps(func)
async def wrapper_func(self: 'Interface', *args, **kwargs):
try:
return await func(self, *args, **kwargs)

3
electrum/lnpeer.py

@ -11,6 +11,7 @@ import os
import time
from typing import Tuple, Dict, TYPE_CHECKING, Optional, Union
from datetime import datetime
import functools
import aiorpcx
@ -289,6 +290,7 @@ class Peer(Logger):
self.announcement_signatures[chan.channel_id].put_nowait(payload)
def handle_disconnect(func):
@functools.wraps(func)
async def wrapper_func(self, *args, **kwargs):
try:
return await func(self, *args, **kwargs)
@ -550,6 +552,7 @@ class Peer(Logger):
# During the channel open flow, if we initiated, we might have used a change address
# of ours in the funding tx. The funding tx is not part of the wallet history
# at that point yet, but we should already consider this change address as 'used'.
@functools.wraps(func)
async def wrapper(self: 'Peer', *args, **kwargs):
funding_tx = kwargs['funding_tx'] # type: PartialTransaction
wallet = self.lnworker.wallet

3
electrum/util.py

@ -45,6 +45,7 @@ import ipaddress
from ipaddress import IPv4Address, IPv6Address
import random
import secrets
import functools
import attr
import aiohttp
@ -1086,6 +1087,7 @@ def make_dir(path, allow_symlink=True):
def log_exceptions(func):
"""Decorator to log AND re-raise exceptions."""
assert asyncio.iscoroutinefunction(func), 'func needs to be a coroutine'
@functools.wraps(func)
async def wrapper(*args, **kwargs):
self = args[0] if len(args) > 0 else None
try:
@ -1105,6 +1107,7 @@ def log_exceptions(func):
def ignore_exceptions(func):
"""Decorator to silently swallow all exceptions."""
assert asyncio.iscoroutinefunction(func), 'func needs to be a coroutine'
@functools.wraps(func)
async def wrapper(*args, **kwargs):
try:
return await func(*args, **kwargs)

Loading…
Cancel
Save