 Good evening everyone. This is my first talk at Montreal Python. It will be of course my first start at PyCon. Since I have a bit of a non-standard background, I'm going to take a couple of minutes to talk about the path I took to be here today. So my first program was actually on that calculator back in the 70s. And in university I had the joy of doing the last Fortran class offered at university and the last punch cards that were needed. And then I discovered C. I consider myself mostly like C is my native language, if you want to put it that way. After I graduated from Polytechnic with as an industrial engineer because it was not cool for a woman to be in computers. It was the start of that feeling. So I graduated as an industrial engineer funnily enough with a specialization in robotics doing calibration. What can I say? Back in 1989. And then I got hired in the industry. I started, I worked as a developer in C and ended up working five years for Softimage. During the years they were bought by Microsoft doing kinematic chains and all that. So that's basically my experience at that time. And then I quit. I am part of the high percentage of women who quit tech decided to have kids. And they were not compatible at the time. And Microsoft I was working 80 hours a week and getting bad refused because the rest of the team were working 100 hours a week. So I mean 100 hours a week and family are just not compatible. So I quit. During the first few years I was at home, I started working on the web in the Netscape era. So I have a little bit of background as a web developer on the back end. Pearl and ASP was coming out at the time. And then through a rock in our plans, we ended up homeschooling the kids. So we have two kids and we homeschool them from basically birth all the way to university. My eldest is about to graduate from McGill. And my youngest is applying this year. So while I was homeschooling I could not develop at all. There was no time left for any type of tech work. So in 2014 I heard PyCon was in Montreal. So I showed up at the young coders workshop figuring I think I can understand what the teacher says and I can turn around and let the kids help the kiddles out. So here's my secret. In 2014 I did not know Python. I had absolutely no Python knowledge when I showed up at the young coders. And at young coders I met Mathieu, who's somewhere around here. Mathieu, there, over there. And he chatted me up and he introduced me to PyLadies. And for the next year I went to every single PyLadies and that's where I learned Python. Honestly, because of the use of homeschooling, when I look at the code I did not remember how to do a loop. I started from scratch again, like totally back to basic. And at that point I decided, okay, can I get back into tech? Is it possible to get back into tech? I had a triple whammy against me. I'm over 50 years old. My CV, basically, depending on how I represent my CV, I have a 10-year gap or a 20-year gap that employers don't like that. And I'm a woman in tech. You know, look around the room, Montreal is a pretty good city for women in tech but still we are a minority. In 2015 I managed to get hired. I got hired by Dexter Industries, which is an American company, but actually everyone is remote. So I can work from Montreal and everybody else is remote. What do we do? We bring robotics to kids. So we're not talking high-end. We're talking really, really low-end. And I was tasked this year in creating a graphical language for our robot. There is one of we, no, not that way. So as I said, low-end little robot that the kids can have in the classroom and we bring it in the actual classroom. It is not part of an afterschool club. It is meant to be used in the actual curriculum. So it's used in English, it's used, of course, in math and sciences. It's used in history, social sciences, and we have curriculum for that. But programming it was the challenge. Teachers are afraid of programming in the classroom and you get kids from every single background. You have kids that are like aces in programming already, they're no more than teacher, and you have kids who are barely interested. So we have to make this fun and approachable. And that's where Blockly comes in. What is Blockly? Anyone here has heard of Blockly before? It's a toolbox made by Google since 2011 that it's basically a UI toolbox that lets you create your own drag-and-drop block-based language. So if I click on this, no, I can't, I'm not on the web. Good thing I have images. So skip an image. So this is the code that you can get over here. You have the categories for the blocks and you drag-and-drop them. So it's very easy for the kids who don't have typing skills yet and they don't even have spelling skills at that point. How many ways can people write backwards? It's impressive. And Blockly lets you generate code from those blocks. So if I click on Python, I would get, from the blocks I had before, I would get this. So, okay, fine. Here's your project, Nicole. Give us a language. You have a background in computer science. You have a background in teaching kids. Actually, I still teach kids with kids called Janes over here. So let's do this. Our goal. We want to control this little robot from a laptop that has just a browser. Nothing needs to be installed on the laptop. And we don't even need an internet connection for that one. The robot has a Raspberry Pi in it, so we can run a web server and communication is through Wi-Fi so the kids don't have to trip over wires in the classroom. So on the Raspberry Pi, I'll have Flask running, communicating with the browser and controlling the go-by-go. So what now? We have this. The Blockly itself is all JavaScript. They didn't say that. And it will give you this generated code as a string. That was my first block. Okay, I'm handed a string. How do I execute it? How do I run that string which thinks it's Python code? Type it. So first attempt, exec, which is also the same as eval, more or less. So exec will let you run, like this, a Python code. And if you please bear with me, oh, this is way, way, way. Ah! Find it back again. Sorry, I'll make a note that I need to have that font bigger. What's my cursor? There it is. Move, move, move, move. How big should I make it? Bigger again? Of course, the window closes. Why don't you cross over? The only thing I didn't plan. That's better? Okay, so if I have, yes, I'm a VI person. And I'm seeing, oh, shoot. My hard drive crashed this weekend, so I had to reinstall everything from scratch. I don't usually have my VI set to show, like, my files do not have the windows ending over there. Oh, yeah. So, basically, I'm going to have in my string drive forward. I knew this would happen. Of course, would this be bigger? That one that's showing my password. There you go. So at that point, the idea was that each block would give us a little piece of code and that we would run them one by one like this. Okay? I'm like in the back of the room, even though we're remote. Okay, how are we going to handle loops over there in Blockly? We can't do this like that. So, of course, we can have one big string. That makes a lot more sense. We'll be able to handle a lot more complex stuff. I don't think I need to actually run it. But what if we are dealing with kids? Kids like huge numbers. If you give them a field to enter something a number, they will enter, 99, 999, 999, and see what it does. Plus, they're beginners. They will give us infinite loop. In the case of exec, if you notice, I don't need to have my libraries in here because the code is in the same process as my web server. So if they put my web server in a loop, it's not quite cool for the web server. So I have to kill my web server to get out of the loop. So exec and eval are not appropriate for this one. So second attempt. Let's go to sub process. Sub process will actually give us a different little process over there. And it is usable because we can actually use a string in the command line of Python, which I didn't know before that. Remember, I'm sort of a beginner with Python. So if you use minus c, you can actually send it to string. And it will execute right there. So we will launch Python using sub process. This is the standard application that you see online for sub process. You're supposed to launch a bunch of them as if they were threads. And then you're supposed to wait for them to finish, and they come back to you. And the thing is, we don't want the web server to wait for the processes because usually we recommend two kids to a robot. So if one of them is running the robot, the other one is already on the computer doing its own thing. So no wait. So what happens if we don't wait? This little robot thing was three. I actually get my prompt back before the program is done, which is what I want. That means control is returned to the web server. But how do I know when the program is done? How do I know when I need to sort out? I think this one is the one with the infinite loop. See? At this point, I've lost control. So I have to go and actually manually find which one it is. And having typos. Having double typos. Wow. Which one do I need to kill? 1, 6, 4, 1, 7 is 1. Got it. And you can actually see from here, it's actually not bad that I got into that. You can actually see my string being displayed. So that's something that we really want to keep doing. So we have to keep track of the process ID. Many deaths of a sub-process. If you do a wait, and thank you, Julia, these are my little drawings. If the main process is stopped while the sub-process goes on and will pick up when the sub-process has ended, that's all good. Or you can actually kill that sub-process with the terminate function. There's also a kill function, but the terminate is slightly nicer. And that is used because we have an emergency stop button on the browser. So whenever they have a runaway robot, they can kill it with the stop button. And this is my boom over there. But what if the program ends nicely, and your web server keeps on going? Hopefully you don't want your web server to finish with the terminate. It should be there until the robot is shut down. I discovered that this leads to zombies. This is the actual technical term. I had never heard of zombies before because of the background that I have. I'm sure if you've done any sys and min stuff, you've heard of them. They were new to me. So I have functions on my code that is actually called hunt for zombies. And we had plenty of fun with that. So this is basically the process, the sub-process ends peacefully and zombifies. So now you'll have to find if you have a zombie and kill it. The silver spare out, whatever it is, however you kill zombies. I send the sick term. Sorry? Yeah, I send sick term. But you have to keep track of them and get them, kill them at one point. So this is basically at this point, that was our version one. And we actually shipped it, and it's being well received. But can we communicate back and forth between that sub-process and the main process? Yes, we can. But I have not found an easy tutorial. And honestly, each time I was looking at those tutorials, because I work part-time, by the way, each time I was looking at those tutorials, my eyes glazed over and I went to big muffins. I work from home. I don't know what my brain did not. It uses pipes and STD in and STD out, and I just could not find how to apply it to what we were doing. And we had a co-worker at that point who was all excited. I have found this brand new library. I don't know if it's new, but he was saying it's new. I don't think it is. So he was really, really pushing to use the multiprocessing library. And that's actually my last slide, because I hate PowerPoint. So let's kill it, because it's in my way. Multiprocessing. This is a standard example of a multiprocessing call. You have a function over here that you want to spawn into a different process. And this is the call where you set up the process and you pass the pointer to the function, a little bit of C talk here, as the target. That works very well, and you can also pass a name to it if you want to keep track of what's what. And you can have a lot of them at the same time. And that is like easy setup, but I need a function to be defined. I have a string. I'm still stuck with that string. I wasn't in a good mood that day, I think. So I decided I'm going to kill that string. And I got it to work. So what I do, I'm going to start from here. I take my string, I'm going to wrap it into a function. And the code is over here. Wrap. So first of all, any new line becomes a new line in a tab, because I'm adding that definition in the top, so everything has to be indented. Fun. And I've decided also to basically at the end of it, instead of going for zombies, why don't I just send a signal back to the main web server? So I'm wrapping my code. I'm adding a path for Python to look for libraries, which is a RAM disk. I am writing that code in the RAM disk. And I'm importing it back, and then I'm reloading it in case it was already imported. If you try to import it twice, it's not going to renew the code, so you have to reload it. Now I have my string in a function ready to use. So I can just send it as a target like this. We added a cute name, because we also have a cleanup back process that we can have, so the name is different. And you start the queue that's part of multiprocessing, and the queue is what allows you to send information back from that sub-process to your server. So for this example, I'm basically just waiting for the end, and then I'm doing a print for it. That was multiprocessing. For Pseudo, it requires Pseudo, which is fine, because the kids never see that. You worked at home. It worked at home. It worked this morning. That code is not defined. OK, well, too bad I'm not debugging in front of you. I'm going to show it to you how it works in here. That allows us to have a print statement from the browser. Actually, this one has a distance sensor, so let's use the distance sensor. We had a big fight whether the default would be inches or centimeters I lost. There you go. Whatever is in front of it is 118 inches away, and the program is done. So I get it from the sensor into the Raspberry Pi into Flask back to the browser. Where to from now? Our next goal is to have two-way communications so that you can actually, as a kid, you could use the arrows in here, send it to your sub-process that's being run to control the robot. Right now, we cannot do that, but with multiprocessing, it's very easy to do. And yeah, so that's the actual goal is to have two-way communications between the two and also parallel coding. Right now, the kids can only have one sequence, but they're used in Scratch to have parallel sequences. So that's the next thing. We are going to move. You possibly noticed that I was using Python 2.2. We are moving to Python 3, because I want to take advantage of the Asyncio library. And that's, again, something that I will be starting from Scratch, because I don't know a thing about it. But it seems to be doing what I want to do. So that's my presentation on handling different processes using the Raspberry Pi. Any questions? Just a little square, a loop. I'll repeat it 10 times. I'll go forward. I'll leave it in one second. It has room. Yeah, it has room. Turn 90 degrees to the left. 10 times is going to be long. Four times is going to do a square. And you want to see it. And you can also show the values here as it's moving around. It's going to give you the readings. So if I remind it again, really annoying that. Invalid readings is when it's too far. That, again, we had a big discussion about what do we tell the kids when it's too far or too close. And right now, it's invalid reading. So there's a lot of multi-threaded stuff going on there and reading the sensors and avoiding collisions between reading in Blockster and reading the sensors in the control panel. But that's not the subject of this talk. There was a lot going on there, too. So I'm at the other end of the spectrum for the robots. This is about $100. Well, we have it in classrooms. And we work with teachers. And I don't know whether it's been, hasn't been long enough for the kids to decide to go into IT or not. And we also differentiate ourselves from Mindstorm, which is very competitive or vented, as this is part of the classroom for every single kid so that no kid is left behind regarding technology. And right now, what we're getting, the feedback that we're getting is that teachers are finding that kids with difficulties in school or kids who are not interested by school absolutely love this. They start the first day of school, they build their robots, and they will use it every single week throughout the year on different subjects with this programming language. Are we limited to Blockster? Absolutely not. We support Python, C, Go, JavaScript, Node.js. There's like seven or eight languages that you can use with that. The robot itself has been used by Google in their research department when they wanted to showcase their Google Cloud API to our surprise when they came out with that. It's like, that's our robot. Amazon and Microsoft are also using it in their research center. We have a lot of people doing masters using that one because it's not the robot that they want, it's the computer vision or whatever, and they don't want to spend time on getting a robot. This one works out of the box. So we've done OpenCV with it. We've done a lot with that, but since I have a somewhat of a teaching background, I ended up developing this language. Yes. Okay. The Project for History, they basically create a map of the States because it's an American company on the floor of their classroom. So they get together and they draw this whole map, and then they have to decide when they were... They have to choose for themselves which vehicle they will use to conquer the West. So they will actually disguise the robot, either in a boat or in one of those wagons, and then they have to program the robot to go a proper way according to their vehicle across the States to conquer the West. Okay, so we're looking at a one-hour class that you can finish in an hour as opposed to writing a book report or something like that. That's the type of curriculum that we have. Yeah, but it gets the kids interested in history. That's the goal. We're really weaving it into the standard curriculum. It's about grade six, by the way, grade five, grade six. And with using a block-based language, everybody in the classroom can code. And it runs Python in the background. You had a question, I think? I had a question in the same question. Yeah. We have great meetings about coming up with ideas of, you know, how do we fit in this type of classroom? So thank you very much.