Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: GlasgowEmbedded/glasgow
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: b5c7f1275341
Choose a base ref
...
head repository: GlasgowEmbedded/glasgow
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 396ddaa37dff
Choose a head ref
  • 2 commits
  • 1 file changed
  • 1 contributor

Commits on Aug 6, 2019

  1. Copy the full SHA
    230e8e7 View commit details
  2. Copy the full SHA
    396ddaa View commit details
Showing with 12 additions and 10 deletions.
  1. +12 −10 software/glasgow/support/pyrepl.py
22 changes: 12 additions & 10 deletions software/glasgow/support/pyrepl.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import code
import asyncio
import builtins
try:
import readline
except ModuleNotFoundError:
@@ -25,7 +26,8 @@ def __init__(self, *args, **kwargs):
except FileNotFoundError:
pass

self._fut = None
self.locals["__name__"] = __name__.split(".")[0]
self._future = None

def save_history(self):
if readline is not None:
@@ -35,15 +37,14 @@ def save_history(self):
def runcode(self, code):
try:
exec(code, self.locals)
builtins = self.locals["__builtins__"]
if "_" in builtins:
if asyncio.iscoroutine(builtins["_"]):
self._fut = builtins["_"] = asyncio.ensure_future(builtins["_"])
if hasattr(builtins, "_"):
if asyncio.iscoroutine(builtins._):
self._future = asyncio.ensure_future(builtins._)
except SystemExit:
raise
except:
self.showtraceback()
if self._fut:
if self._future:
raise _FutureResult

async def interact(self):
@@ -54,13 +55,14 @@ async def interact(self):
except _FutureResult:
self.resetbuffer()
try:
if not self._fut.done():
result = await self._fut
if not self._future.done():
result = await self._future
else:
result = self._fut.result()
result = self._future.result()
builtins._ = result
if result is not None:
print(repr(result))
except Exception as e:
self.showtraceback()
self._fut = None
self._future = None
self.save_history()