Load / reload part of code in Python without restarting the main script

Introduction

I have been practicing with Twisted for the past few days, raising python less than a month ago. My first wish was to play with what I know and use every day, IRC. I got the basic IRC connection and works using ircLogBot.py .

Question

I want to have some arbitrary code that fires whenever an IRC event is received (PRIVMSG / CTCP / JOIN / PART), and for debugging purposes, I would like to make changes to this piece of code and then reload it without disconnecting everything script and reconnecting to the IRC server.

Concluding observations

This should not be a solution that includes Twisted, as I do not quite understand it yet. Although I suppose that this is what has been distorted, being an event-based framework, is likely to succeed.

+5
source share
4 answers

Schedule a recurring event (every few seconds) to reload the module being debugged. For this purpose, use the built -in reload () function .

You might want to wrap it in try / except to handle the case when you enter an error in a debugged module. This will keep the server furious before errors :-)

+3
source

Twisted twisted.python.rebuild, Python reload. , Python , . ( , , , __init__, , rebuild.Sensitive .)

- , , , , . Linux Twisted inotify , OS X cfreactor FSEvents API PyObjC. ( , win32, .)

+9

, " livecoding ', ; . , , " livecoding" (), , .

- , reload, . , .

+2

. , . . , .

.

0

All Articles