Skip to content

Commit

Permalink
release 0.0.54 (#49)
Browse files Browse the repository at this point in the history
* fix when __globals__.py doesn't exist

---------

Co-authored-by: nggit <[email protected]>
  • Loading branch information
nggit and nggit authored Nov 11, 2024
1 parent e1e1a1e commit 47ba97d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion httpout/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright (c) 2024 nggit

__version__ = '0.0.53'
__version__ = '0.0.54'
__all__ = ('HTTPOut',)

from .httpout import HTTPOut # noqa: E402
14 changes: 6 additions & 8 deletions httpout/httpout.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ async def _on_worker_start(self, **worker):
sys.path.insert(0, document_root)

# provides __globals__, a worker-level context
worker['__globals__'] = new_module('__globals__')
module = new_module('__globals__')
worker['__globals__'] = module or ModuleType('__globals__')
worker['modules'] = {'__globals__': worker['__globals__']}
py_import = builtins.__import__

def wait(coro, timeout=None):
return asyncio.run_coroutine_threadsafe(coro, loop).result(timeout)
Expand Down Expand Up @@ -77,8 +79,6 @@ def load_module(name, globals, level=0):

return module

py_import = builtins.__import__

def ho_import(name, globals=None, locals=None, fromlist=(), level=0):
if (name not in sys.builtin_module_names and
globals is not None and '__file__' in globals and
Expand Down Expand Up @@ -147,17 +147,15 @@ def ho_import(name, globals=None, locals=None, fromlist=(), level=0):
return py_import(name, globals, locals, fromlist, level)

builtins.__import__ = ho_import
builtins.__globals__ = worker['__globals__']

g.wait = wait
g.caches = {}
g.executor = MultiThreadExecutor(thread_pool_size)
g.executor.start()

if worker['__globals__']:
builtins.__globals__ = worker['__globals__']
exec_module(worker['__globals__'])
else:
builtins.__globals__ = ModuleType('__globals__')
if module:
exec_module(module)

async def _on_worker_stop(self, **worker):
g = worker['globals']
Expand Down

0 comments on commit 47ba97d

Please sign in to comment.