sugarlabs / maze-activity

A simple maze game for the Sugar learning environment
GNU General Public License v3.0
1 stars 10 forks source link

Port to Python 3 #31

Closed kiy4h closed 4 years ago

kiy4h commented 4 years ago

Tested on Sugar Desktop.

quozl commented 4 years ago

Thanks. Suffers from the same visual regression as https://github.com/sugarlabs/maze-activity/pull/29, so please fix this or explain why it can't be fixed? I imagine it may have something to do with Python 3 division now yielding floating point, but I've not checked.

kiy4h commented 4 years ago

Ah, that was because of a few float divisions. Fixed now!

quozl commented 4 years ago

Thanks. Tested. Yes, it does solve the visual regression. Tested collaboration; it doesn't share the maze, and both instances have this in logs;

Traceback (most recent call last):
  File "/usr/share/sugar/activities/Maze.activity/activity.py", line 171, in _shared_cb
    self._setup()
  File "/usr/share/sugar/activities/Maze.activity/activity.py", line 188, in _setup
    self.shared_activity.telepathy_conn, self.pservice)
  File "/usr/share/sugar/activities/Maze.activity/textchannel.py", line 23, in __init__
    m = self._text_chan[TelepathyGLib.IFACE_CHANNEL].\
TypeError: 'Interface' object is not subscriptable

I don't understand your change to _setup(). Can you explain? 791f51ca3078b9c6dfaa6a4c20e3eb360359081b

Aniket21mathur commented 4 years ago

I also don't understand your change in _setup(), it seems to break collaboration, as it is working fine when tested with master.

kiy4h commented 4 years ago

Oh well, I guess I have burnt out a few nights ago. I've reverted the changes in activity.py

quozl commented 4 years ago

Thanks. Tested collaboration. Sharing instance completes sharing. Joining instance stalls with message "Joining a maze ... Connecting ...". Sharing instance logs a message;

1575956718.693901 ERROR root: Message from unknown buddy AAAAB3NzaC...pdNQ==

This is emitted by the message handler msg_received when it does not find the key (a unique identifier for a user) in the list of remote players.

By adding import pdb; pdb.set_trace() and exploring the program state with pdb, the cause is that the key is present as a repr()'d Bytes object rather than a Str object. A classic Python 3 porting bug.

We may have fixed this before in other activities.

TextChannelWrapper in textchannel.py is by the same author as TextChannelWrapper in collabwrapper.py.

It may be that this is an opportunity to adopt the Python 3 ported CollabWrapper source code for this class.

However, I'm interrupted by something else now, and have to stop. Hope this helps. I may get back to it and edit my comment.

quozl commented 4 years ago

Tested 0019735. You're getting closer, I reckon. I think the joined message may be the key. I've been debugging a bit more. In game.py at buddy_joined, with a _pdb.settrace;

In both cases, the key is a str(bytes), instead of a a str. i.e. what you get from typing this into a Python 3 prompt; str(b'testing')

Makes me think we have a toolkit problem, or my Sugar Toolkit is out of date here. Do you reproduce the problem I see?

quozl commented 4 years ago

I've found as above that Buddy.get_key can return None for a while because the GetProperties call in Buddy.__init__ is asynchronous; it happens at the same time in Python 3, but seemed to be completed earlier in Python 2.

I'm not sure which other activities rely on the Buddy key as an identifier, but since Maze was written the Buddy class has grown some other features, among which is contact_id, which is used in src/sugar3/presence/activity.py as an identifier. I've experimented with changing Maze to use that, and it seems to work better. Here's my change in progress;

diff --git a/activity.py b/activity.py
index 6a6f618..9f2c3b8 100755
--- a/activity.py
+++ b/activity.py
@@ -241,7 +242,7 @@ class MazeActivity(activity.Activity):
         if self.text_channel:
             # FIXME: can't identify the sender at the other end,
             # add the pubkey to the text message
-            self.text_channel._send('%s|%s' % (self.my_key, message))
+            self.text_channel._send(message)

     def write_file(self, file_path):
         logging.debug('Saving the state of the game...')
diff --git a/game.py b/game.py
index 38ff5e4..81876ce 100644
--- a/game.py
+++ b/game.py
@@ -527,8 +527,8 @@ class MazeGame(Gtk.DrawingArea):
             logging.debug("Join: %s - %s", buddy.props.nick,
                           buddy.props.color)
             player = Player(buddy)
-            player.uid = buddy.get_key()
-            self.remoteplayers[buddy.get_key()] = player
+            player.uid = buddy.contact_id
+            self.remoteplayers[player.uid] = player
             self.allplayers.append(player)
             self.allplayers.extend(player.bonusPlayers())
             self._mark_point_dirty(player.position)
@@ -562,24 +562,23 @@ class MazeGame(Gtk.DrawingArea):

     def buddy_left(self, buddy):
         logging.debug('buddy left %s %s', buddy.__class__, dir(buddy))
-        if buddy.get_key() in self.remoteplayers:
-            player = self.remoteplayers[buddy.get_key()]
+        if buddy.contact_id in self.remoteplayers:
+            player = self.remoteplayers[buddy.contact_id]
             logging.debug("Leave: %s", player.nick)
             self._mark_point_dirty(player.position)
             self.allplayers.remove(player)
             for bonusplayer in player.bonusPlayers():
                 self._mark_point_dirty(bonusplayer.position)
                 self.allplayers.remove(bonusplayer)
-            del self.remoteplayers[buddy.get_key()]
+            del self.remoteplayers[buddy.contact_id]

     def msg_received(self, buddy, message):
         logging.debug('msg received %s', message)
-        print('msg received %s', message)
-        key, message = message.split('|')
         if message.startswith('maze'):
             self.handleMessage(None, message)
             return

+        key = buddy.contact_id
         if key in self.remoteplayers:
             player = self.remoteplayers[key]
             try:

What do you think?

It doesn't solve why get_key returns a badly quoted string though.

kiy4h commented 4 years ago

I have the same unknown buddy error;

1575956718.693901 ERROR root: Message from unknown buddy AAAAB3NzaC...ZuWg==

But I haven't been exploring around with pdb.set_trace(), which is what I'm trying to do now.

The changes are looking good! It's nice to hear that the Maze activity is doing better.

quozl commented 4 years ago

Problem with my change above is that it breaks interoperability between versions; everyone on the same network would have to upgrade to the new version. It would be better if I can figure out how to detect completion of the asynchronous D-Bus method.

kiy4h commented 4 years ago

I see. So this problem doesn't occur in the Python 2 version?

quozl commented 4 years ago

Yes, this problem doesn't occur in the Python 2 version. I've used the notify::key signal of Buddy successfully, but need to try again with notify::color too, as the signal for key arrives before the color property is set, and player.py wants the color.

quozl commented 4 years ago

I've fixed it. Will push a patch.

quozl commented 4 years ago

Please review f112273 commit message and change, and let me know what you think.

kiy4h commented 4 years ago

Alright, I've just pulled from both of the VMs. But now my second VM won't update my first VM's maze position, see attachment: Annotation 2019-12-11 145251

Is this a long-known issue? PS: I started running the maze on my second VM (the one on the right), then the left VM joined the activity.

EDIT: I forget to pull from the other VM (I swear I did, machines are weird), this has been resolved

quozl commented 4 years ago

No, that's not right. I'll have a look again.

quozl commented 4 years ago

I haven't been able to make it happen. Perhaps it is https://github.com/sugarlabs/sugar/issues/840. Workaround for that is to make sure to wait for the buddy icon to disappear and reappear on the network view (F1) before starting the test. You could check your "msg received" print to see if the data flow stops. In my current tests, I've moved it below the split so the user key is not printed for every message; it makes it easier to read.

kiy4h commented 4 years ago

I think so, sometimes the buddy icon appears and disappears on the F1 view. But now I've got it working.

kiy4h commented 4 years ago

This might be unrelated to the issue but after a restart, the maze activity on the favorite view is gone. I still have it on ~/Activities/, why's this?

quozl commented 4 years ago

This might be unrelated to the issue but after a restart, the maze activity on the favorite view is gone. I still have it on ~/Activities/, why's this?

I've no idea, sorry. I suggest checking shell.log for interesting things that happen at the same time.

kiy4h commented 4 years ago

Hmm, this is what's in shell.log:

1576051576.854146 ERROR root: No bundle in '/home/kiy4h/Activities/activity'
1576051576.854899 ERROR root: No bundle in '/home/kiy4h/Activities/po'
1576051576.855401 ERROR root: No bundle in '/home/kiy4h/Activities/docs'
1576051576.855845 ERROR root: No bundle in '/home/kiy4h/Activities/icons'
1576051576.856282 ERROR root: No bundle in '/home/kiy4h/Activities/.git'
/usr/lib/python3/dist-packages/gi/overrides/Gtk.py:1641: Warning: g_value_transform: assertion 'G_IS_VALUE (src_value)' failed
  return _Gtk_main(*args, **kwargs)
/usr/lib/python3/dist-packages/gi/overrides/Gtk.py:1641: Warning: unable to set property 'buddy' of type 'PyObject' from value of type '(null)'
  return _Gtk_main(*args, **kwargs)
1576051615.457347 ERROR root: Launcher was not registered for b0155a49b7c20dfa20b1e35160fddd46610e7703
1576051629.478665 WARNING root: Ignoring shared activity we dont have
1576051629.479135 WARNING root: Ignoring shared activity we dont have
1576051631.107545 ERROR root: set_active() failed: org.freedesktop.DBus.Error.NoReply: Message recipient disconnected from message bus without replying
1576051633.173026 ERROR root: set_active() failed: org.freedesktop.DBus.Error.NoReply: Message recipient disconnected from message bus without replying
Traceback (most recent call last):
  File "/usr/lib/python3.7/dist-packages/jarabe/model/neighborhood.py", line 1063, in __activity_removed_cb
    self._shell_model.remove_shared_activity(activity_id)
  File "/usr/lib/python3.7/dist-packages/jarabe/model/shell.py", line 528, in remove_shared_activity
    del self._shared_activities[activity_id]
KeyError: dbus.String('c9cdd4f0bd31b96aaedb4d39233375b3e42cb74c')
Traceback (most recent call last):
  File "/usr/lib/python3.7/dist-packages/jarabe/desktop/meshbox.py", line 409, in _buddy_removed_cb
    self._remove_buddy(buddy_model)
  File "/usr/lib/python3.7/dist-packages/jarabe/desktop/meshbox.py", line 435, in _remove_buddy
    icon = self._buddies[buddy_model.props.key]
KeyError: dbus.ByteArray(b'AAAAB3NzaC1kc3MAAACBAK+J8cfL9MS33MA+10eEUVhcBs6IwNP6EqjPDkC6SlqLzcDpGTFO8ankYMd9+wcuvgqNGRm0INpvJFgbrhWfQyTa0dCJB9jqxactUWWwRCBdYhrxtN7roifkYIlEoq/Uuqn/DQyel3JmNSUfbKZGZQPfYI0pzslcy+NfHuSV2+JfAAAAFQCOmmk2LFd43w+4SmQGM7OzXXB6/QAAAIBA3okRKMfrC5to1SONCjXKGwA4C1HJM2Z1mB15IIMzKyHBpVtiMnfsKrkPaxWxkOELZLUQmP7Exob2dKSWmzzNnawrCpgsMqj0RF/45fui6TN3FULxoIyqIVtQeDpQdxS9om5Eq3YN0BmYSomM6ipsK+Pzuwb020CJL8+vKcST8gAAAIADCocpBTM3dyucWy9o5r8T9DcOmFcXTKr+7Jo45sSAtzO+CCGL0D/0jbTLWyptufZ4rm0C7cr7SOhQ1HvqqYreVfF6dF4uBSCO5WYCfoA4+z2ovxtJmt709Xw/p8IVY7osia4wgi5sA4GyaDXU+0GozOBrghLWETAhlxFxOxZuWg==', variant_level=1)
1576051659.556256 WARNING root: Ignoring shared activity we dont have
1576051659.556775 WARNING root: Ignoring shared activity we dont have
Traceback (most recent call last):
  File "/usr/lib/python3.7/dist-packages/jarabe/model/neighborhood.py", line 1063, in __activity_removed_cb
    self._shell_model.remove_shared_activity(activity_id)
  File "/usr/lib/python3.7/dist-packages/jarabe/model/shell.py", line 528, in remove_shared_activity
    del self._shared_activities[activity_id]
KeyError: dbus.String('537f65533d38b24cf459c069aa4da6bf8f8f4e94')
Traceback (most recent call last):
  File "/usr/lib/python3.7/dist-packages/jarabe/desktop/meshbox.py", line 409, in _buddy_removed_cb
    self._remove_buddy(buddy_model)
  File "/usr/lib/python3.7/dist-packages/jarabe/desktop/meshbox.py", line 435, in _remove_buddy
    icon = self._buddies[buddy_model.props.key]
KeyError: dbus.ByteArray(b'AAAAB3NzaC1kc3MAAACBAK+J8cfL9MS33MA+10eEUVhcBs6IwNP6EqjPDkC6SlqLzcDpGTFO8ankYMd9+wcuvgqNGRm0INpvJFgbrhWfQyTa0dCJB9jqxactUWWwRCBdYhrxtN7roifkYIlEoq/Uuqn/DQyel3JmNSUfbKZGZQPfYI0pzslcy+NfHuSV2+JfAAAAFQCOmmk2LFd43w+4SmQGM7OzXXB6/QAAAIBA3okRKMfrC5to1SONCjXKGwA4C1HJM2Z1mB15IIMzKyHBpVtiMnfsKrkPaxWxkOELZLUQmP7Exob2dKSWmzzNnawrCpgsMqj0RF/45fui6TN3FULxoIyqIVtQeDpQdxS9om5Eq3YN0BmYSomM6ipsK+Pzuwb020CJL8+vKcST8gAAAIADCocpBTM3dyucWy9o5r8T9DcOmFcXTKr+7Jo45sSAtzO+CCGL0D/0jbTLWyptufZ4rm0C7cr7SOhQ1HvqqYreVfF6dF4uBSCO5WYCfoA4+z2ovxtJmt709Xw/p8IVY7osia4wgi5sA4GyaDXU+0GozOBrghLWETAhlxFxOxZuWg==', variant_level=1)
1576051996.039461 WARNING root: no data for selection target MULTIPLE.
1576052143.626659 ERROR root: set_active() failed: org.freedesktop.DBus.Error.NoReply: Message recipient disconnected from message bus without replying
1576052156.487895 ERROR root: Launcher was not registered for da1ba9a1cf99dbd48e866762292a3f843f1b234b
1576052192.350655 WARNING root: Ignoring shared activity we dont have
1576052192.353218 WARNING root: Ignoring shared activity we dont have
Traceback (most recent call last):
  File "/usr/lib/python3.7/dist-packages/jarabe/model/neighborhood.py", line 1063, in __activity_removed_cb
    self._shell_model.remove_shared_activity(activity_id)
  File "/usr/lib/python3.7/dist-packages/jarabe/model/shell.py", line 528, in remove_shared_activity
    del self._shared_activities[activity_id]
KeyError: dbus.String('da1ba9a1cf99dbd48e866762292a3f843f1b234b')
1576052283.346964 ERROR root: set_active() failed: org.freedesktop.DBus.Error.NoReply: Message recipient disconnected from message bus without replying
1576052291.512578 ERROR root: set_active() failed: org.freedesktop.DBus.Error.NoReply: Message recipient disconnected from message bus without replying
Traceback (most recent call last):
  File "/usr/lib/python3.7/dist-packages/jarabe/model/neighborhood.py", line 1035, in __activity_updated_cb
    bundle = registry.get_bundle(properties['type'])
KeyError: 'type'
1576052317.478579 ERROR root: set_active() failed: org.freedesktop.DBus.Error.NoReply: Message recipient disconnected from message bus without replying
Traceback (most recent call last):
  File "/usr/lib/python3.7/dist-packages/jarabe/desktop/meshbox.py", line 409, in _buddy_removed_cb
    self._remove_buddy(buddy_model)
  File "/usr/lib/python3.7/dist-packages/jarabe/desktop/meshbox.py", line 435, in _remove_buddy
    icon = self._buddies[buddy_model.props.key]
KeyError: dbus.ByteArray(b'AAAAB3NzaC1kc3MAAACBAK+J8cfL9MS33MA+10eEUVhcBs6IwNP6EqjPDkC6SlqLzcDpGTFO8ankYMd9+wcuvgqNGRm0INpvJFgbrhWfQyTa0dCJB9jqxactUWWwRCBdYhrxtN7roifkYIlEoq/Uuqn/DQyel3JmNSUfbKZGZQPfYI0pzslcy+NfHuSV2+JfAAAAFQCOmmk2LFd43w+4SmQGM7OzXXB6/QAAAIBA3okRKMfrC5to1SONCjXKGwA4C1HJM2Z1mB15IIMzKyHBpVtiMnfsKrkPaxWxkOELZLUQmP7Exob2dKSWmzzNnawrCpgsMqj0RF/45fui6TN3FULxoIyqIVtQeDpQdxS9om5Eq3YN0BmYSomM6ipsK+Pzuwb020CJL8+vKcST8gAAAIADCocpBTM3dyucWy9o5r8T9DcOmFcXTKr+7Jo45sSAtzO+CCGL0D/0jbTLWyptufZ4rm0C7cr7SOhQ1HvqqYreVfF6dF4uBSCO5WYCfoA4+z2ovxtJmt709Xw/p8IVY7osia4wgi5sA4GyaDXU+0GozOBrghLWETAhlxFxOxZuWg==', variant_level=1)
Traceback (most recent call last):
  File "/usr/lib/python3.7/dist-packages/jarabe/desktop/meshbox.py", line 409, in _buddy_removed_cb
    self._remove_buddy(buddy_model)
  File "/usr/lib/python3.7/dist-packages/jarabe/desktop/meshbox.py", line 435, in _remove_buddy
    icon = self._buddies[buddy_model.props.key]
KeyError: dbus.ByteArray(b'AAAAB3NzaC1kc3MAAACBAK+J8cfL9MS33MA+10eEUVhcBs6IwNP6EqjPDkC6SlqLzcDpGTFO8ankYMd9+wcuvgqNGRm0INpvJFgbrhWfQyTa0dCJB9jqxactUWWwRCBdYhrxtN7roifkYIlEoq/Uuqn/DQyel3JmNSUfbKZGZQPfYI0pzslcy+NfHuSV2+JfAAAAFQCOmmk2LFd43w+4SmQGM7OzXXB6/QAAAIBA3okRKMfrC5to1SONCjXKGwA4C1HJM2Z1mB15IIMzKyHBpVtiMnfsKrkPaxWxkOELZLUQmP7Exob2dKSWmzzNnawrCpgsMqj0RF/45fui6TN3FULxoIyqIVtQeDpQdxS9om5Eq3YN0BmYSomM6ipsK+Pzuwb020CJL8+vKcST8gAAAIADCocpBTM3dyucWy9o5r8T9DcOmFcXTKr+7Jo45sSAtzO+CCGL0D/0jbTLWyptufZ4rm0C7cr7SOhQ1HvqqYreVfF6dF4uBSCO5WYCfoA4+z2ovxtJmt709Xw/p8IVY7osia4wgi5sA4GyaDXU+0GozOBrghLWETAhlxFxOxZuWg==', variant_level=1)
1576052379.691172 ERROR root: set_active() failed: org.freedesktop.DBus.Error.NoReply: Message recipient disconnected from message bus without replying
1576052680.417063 WARNING root: no data for selection target MULTIPLE.
1576052680.434160 WARNING root: no data for selection target NULL.
1576052685.413262 WARNING root: no data for selection target MULTIPLE.
1576052685.420938 WARNING root: no data for selection target NULL.
quozl commented 4 years ago

Covers a long time, based on the time_t time stamps. Any idea when you saw it happen?

kiy4h commented 4 years ago

I mistake putting the whole maze-activity files in ~/Activities, putting them in a folder solved the problem.