Skip to content

Commit

Permalink
fix when __globals__.py doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
nggit committed Nov 11, 2024
1 parent e1e1a1e commit 660480a
Showing 1 changed file with 6 additions and 8 deletions.
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 660480a

Please sign in to comment.