Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Pythonista 1.6 Beta
-
@wradcliffe: confirmed in 1.5.
-
@wradcliffe
Sorry about the late reply. The forum was down last time I tried answering. My script is a little too long for this thread, so I have removed almost everything except the sending thread. (I will post the whole thing to GitHub once it's a little more complete.) The MipManager starts the SpeedUpdater thread once it gets the write characteristic in a callback. My UI calls action methods in MipManager (not shown), which either sets the current speed or turn in the SpeedUpdater, or occasionally queues a special command. Currently, I only send other commands when the robot has fallen over in order to attempt to get up (something the original app doesn't do at all), so the simple timing works. Finally, when my UI is closed, I call the shutdown method of SpeedUpdater via the MipManager.Note that I'm not sure of the thread safety of this code or of Queue.Queue. I just noticed that the threading support was closely modeled after Java and hoped the memory model would be too.
import cb import threading import Queue class SpeedUpdater(threading.Thread): def __init__(self, peripheral, characteristic): threading.Thread.__init__(self) self.peripheral = peripheral self.characteristic = characteristic self.state_lock = threading.Condition() self.keep_alive = True self.speed_code = 0 self.turn_code = 0 self.queue = Queue.Queue() def run(self): keep_alive = True while keep_alive: try: msg = self.queue.get_nowait() self.peripheral.write_characteristic_value(self.characteristic, msg, False) except Queue.Empty: with self.state_lock: self.state_lock.wait(0.05) speed_code = self.speed_code turn_code = self.turn_code if (speed_code != 0) or (turn_code != 0): msg = chr(0x78)+chr(speed_code) + chr(turn_code) self.peripheral.write_characteristic_value(self.characteristic, msg, False) with self.state_lock: keep_alive = self.keep_alive def set_speed(self, speed_code): with self.state_lock: self.speed_code = speed_code def set_turn(self, turn_code): with self.state_lock: self.turn_code = turn_code def queue_cmd(self, cmd): self.queue.put(cmd) def shutdown(self): with self.state_lock: self.keep_alive = False self.state_lock.notifyAll() self.join() class MiPManager (object): def __init__(self): self.state_lock = threading.RLock() self.peripheral = None self.speed_updater = None def did_discover_characteristics(self, s, error): log('Did discover characteristics...') for c in s.characteristics: if c.uuid == 'FFE9': with self.state_lock: self.speed_updater = SpeedUpdater(self.peripheral, c) self.speed_updater.start()
-
@mteep - did you determine that the RLock used in the MiPManager object was necessary to prevent crashes?
-
@wradcliffe
Not really, I just synchronized everything to be safe. (Absence of a crash doesn't make it safe.) I use the RLock for all potentially concurrently accessed state in MipManager, which is more than I included above. Also, the self.speed_updater state is accessed by my code from two threads (UI and main). I used RLock instead of Lock since it has nice properties that I am well used to. -
I sent an email. Hope I can get te beta soon
-
I sent you an email. Can't wait to test the Beta!
-
I have just sent my name in, hope the line isn't long!
-
I would be highly interested in being a test guinea pig 😃. As a researcher who depends on Python for simulations, Pythonista is a blessing.
-
Python 2.7.10 final candidate 1
is now out and2.7.10 is scheduled
to be released in 9 days. -
@OMZ: There is a "glitch" in numpy. I get the following trying to do an import:
Loading NumPy... Traceback (most recent call last): File "/var/mobile/Containers/Data/Application/762ACFDE-3824-4115-AF2E-EDE94F8CB4AF/Documents/Examples/Function Plot.py", line 7, in <module> import numpy File "/private/var/mobile/Containers/Bundle/Application/400D5B78-8EA1-4AD3-AEE4-EE1AE9DBF78E/Pythonista.app/pylib_ext/numpy/__init__.py", line 154, in <module> from . import add_newdocs ImportError: cannot import name add_newdocs
-
@poly -- not sure if this is the same problem, but I've found similar import problems can happen if I cancel a script that imports numpy without letting it complete.
I think numpy gets partially imported, and entries start getting created in sys.modules, but it gets cancelled and therefore is just totally confused. restarting pythonista can help. I think I also had luck with a script that crawled through sys.modules, and
del
'd any entries starting with numpy.I have imported numpy in the beta without problems -- you just have to make sure the first time is a clean import.
-
I found a bug with the autocompletion which causes Pythonista to crash.
Suppose you have a generator:
def fibonacci_gen(up_to): count = 0 var1 = 0 var2 = 1 while count <= up_to: yield var1 count += 1 var1,var2 = var2,var1+var2
If you now try to write
gen = fibonacci_gen(10) number = gen.next()
Pythonista crashes a few seconds after writing the dot behind the gen. If you write .next() somewhere else and copy it you can paste it in and it works fine.
-
@JonB - as always, you're correct. restart fixed it.
@Moe - a VERRY unreproducible bug that @OMZ is chasing. It's seems to always involve instance variable or methods, but not all objects and not every time. Best suggestion - mistype the object name intentionally to suppress the autocompletion and go back after the fact and correct.
However, yours fits the bill of reproducible and pretty small. Even this blows it up:
def gen(x): count = 0 while count < x: yield count count += 1 mygen = gen(10) print mygen.next()
-
FYI, just noticed there is a new beta posted, which supposedly fixes this problem.
-
All I see is a beta that expires in 7 days, which I would expect is the current one. @OMZ please clarify?
-
Testflight says the current beta expires Saturday May 30, a week from now. I haven't heard of any other updates.
-
I have 160014 ( I recently got a new device, and had installed test flight from scratch). Maybe I missed when this was updated.
The following does still crash though:def gen(): yield 1 x=gen() x.
Here are the 160014 release notes. Maybe I just missed this one on my old device.
Build 160014
-
Experimental Apple Watch support – the Pythonista Watch App allows you to launch scripts in the special "Watch" folder. The scripts still run on the iPhone (usually in the background) – the Watch basically just acts a remote control. Console output appears on the watch, including images, but things like
console.set_font()
orconsole.clear()
are not supported. The only way to get user input is currently to callraw_input()
. This brings up the dictation interface on the Watch with an optional list of suggestions to pick from. To set the list of text input suggestions, callappex.watch.set_input_suggestions()
beforeraw_input
. I'm not sure yet how useful this actually is, and if I'll include it in the final release. -
Added a Done button in the console output panel of the app extension
-
Cmd-Left/Right shortcuts (external keyboard) should work properly now
-
Background audio (experimental) – Note: This has the side effect of the mute switch being ignored when playing audio (like in pretty much all music/video player apps). You can also abuse this to make your script run in the background indefinitely by looping a silent track (can be useful for servers and the like).
-
New
is_authorized()
functions in thelocation
,contacts
,reminders
andphotos
modules -
New
did_pause
anddid_resume
methods that can be overridden insk.Scene
subclasses to handle interruptions (e.g. when the app is backgrounded) -
New
console.is_in_background()
function to determine whether Pythonista is currently the foreground app or not -
Fixed crash when importing
requests
in the app extension -
Fixed crash when initializing
sound.MIDIPlayer
without an explicit soundbank path (the "Random MIDI Melody" example shouldn't crash anymore) -
Fixed crashes related to code completion (somewhat hard to reproduce, so I'm not 100% sure)
-
Fixed
ui.View.bounds
(and a couple of other attributes) returning aRect
, but accepting only a tuple (any 4-number sequence should work now) -
Geometry types in the
sk
andui
modules (sk.Rect
,sk.Point
...) support slicing now (slices are always tuples) -
Reverted to an older version of
requests
for now to get rid of "InsecurePlatform" warnings that are logged to the console. I'm well aware that this isn't an actual solution, but a real fix turns out to be non-trivial to implement (the cleanest approach would be to upgrade to Python 2.7.9, but this is quite a lot of work and I'm not sure if I want to get into that for 1.6)
-
-
Btw:omz, how is the background audio enabled? Is this just automatically done in the
sound.Player
class? -
Python 2.7.10 is now out... https://hg.python.org/cpython/raw-file/15c95b7d81dc/Misc/NEWS
-
@JonB This is an older beta.