Skip to content

Commit

Permalink
Merge branch 'main' of github.com:xlwings/xlwings
Browse files Browse the repository at this point in the history
  • Loading branch information
fzumstein committed Aug 26, 2023
2 parents 5fc2a65 + c0b93e0 commit e4a1ef6
Showing 1 changed file with 6 additions and 39 deletions.
45 changes: 6 additions & 39 deletions xlwings/udfs.py
@@ -1,25 +1,19 @@
import asyncio
import json
import sys

if sys.version_info >= (3, 7):
from asyncio import get_running_loop
else:
from asyncio import get_event_loop as get_running_loop

import concurrent
import copy
import functools
import inspect
import json
import logging
import os
import os.path
import re
import sys
import tempfile
import threading
from importlib import (
import_module,
reload, # requires >= py 3.4
reload,
)
from random import random

Expand All @@ -39,29 +33,10 @@
logger = logging.getLogger(__name__)
cache = {}

if sys.version_info >= (3, 7):
com_executor = concurrent.futures.ThreadPoolExecutor(
initializer=pythoncom.CoInitialize
)

def backcompat_check_com_initialized():
pass

else:
com_executor = concurrent.futures.ThreadPoolExecutor()
com_is_initialized = threading.local()

def backcompat_check_com_initialized():
try:
com_is_initialized.done
except AttributeError:
pythoncom.CoInitialize()
com_is_initialized.done = True
com_executor = concurrent.futures.ThreadPoolExecutor(initializer=pythoncom.CoInitialize)


async def async_thread(base, my_has_dynamic_array, func, args, cache_key, expand):
backcompat_check_com_initialized()

try:
if expand:
stashme = await base.get_formula_array()
Expand All @@ -70,7 +45,7 @@ async def async_thread(base, my_has_dynamic_array, func, args, cache_key, expand
else:
stashme = await base.get_formula()

loop = get_running_loop()
loop = asyncio.get_running_loop()
cache[cache_key] = await loop.run_in_executor(
com_executor, functools.partial(func, *args)
)
Expand Down Expand Up @@ -301,15 +276,7 @@ async def _com(self, fn, *args, backoff=1):
a cap.
"""

loop = get_running_loop()

if sys.version_info[:2] <= (3, 6):

def _fn(fn, *args):
backcompat_check_com_initialized()
return fn(*args)

fn = functools.partial(_fn, fn)
loop = asyncio.get_running_loop()

try:
return await loop.run_in_executor(
Expand Down

0 comments on commit e4a1ef6

Please sign in to comment.